I am using the standard GridView.
I have this part working so far.
<asp:HyperLinkField ShowHeader="true" DataTextField="id" DataNavigateUrlFields="id"
DataNavigateUrlFormatString="edit.aspx?id={0}"
DataTextFormatString="Edit" />
However each page needs a 'number' and a 'userid' parameter.
I cannot figure out how to add these parameters to the above HyperLinkField.
<asp:HyperLinkField ShowHeader="true" DataTextField="id"
DataNavigateUrlFields="id"DataNavigateUrlFormatString="edit.aspx?id={0}
&number=Request.QueryString["number"]&
userid=Request.QueryString["userid"]" DataTextFormatString="Edit" />
Can someone tell me what I am missing to be able to add this custom URL to my HyperLinkField?
Try using a templatefield, something like (untested):
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<a href='<%# "edit.aspx?id="+Eval("id") + "&number=" +Request.QueryString["number"]+"&userid=" +Request.QueryString["userid"] %>'>Edit</a>
</ItemTemplate>
</asp:TemplateField>
Related
I'm trying to retrieve a URL parameter and pass it into a HyperLinkField inside my GridView.
The URL looks like http://application.com/dynamic.aspx?locale=us. I need to pull the value of the locale param and include it in the asp:HyperLinkField. I know that I can retrieve this param in the code behind like this:
Request.QueryString["locale"].ToString()
But is it possible to retrieve this value inside the .aspx?
<asp:HyperLinkField DataTextField="ref_id" DataNavigateUrlFields="???,ref_id" DataNavigateUrlFormatString="dynamic.aspx?locale={0}&id={1}" Text="ID" HeaderText="ID" SortExpression="ref_id" >
Better switch to a TemplateField. You have much more control that way.
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# string.Format("/dynamic.aspx?locale={0}&id={1}", Request.QueryString["locale"], Eval("ref_id")) %>'><%# Eval("ref_id") %></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
I need to add column with button in GridView ? i tied with asp:button i got error also i tried asp:ButtonField i got this error:
"Error Creating Control - narudzbaGridType 'System.Web.UI.WebControls.ButtonField' does not have a public property named 'ID'.
but i gave ID name to my Button field asp:ButtonField ID="example"
<asp:GridView ID="narudzbaGrid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Let" HeaderText="Let"/>
<%--<asp:BoundField DataField="Kolicina" HeaderText="Kolicina"/>--%>
</Columns>
</asp:GridView>
You can use TemplateField like this (add to columns block):
<asp:templatefield headertext="Author Name">
<itemtemplate>
<asp:button id="buttonl"
Text= 'Click Me'
runat="server"/>
</itemtemplate>
</asp:templatefield>
Hi you need to add an TemplateField. Everybody like use ImageButton but if you want use other control go ahead.
<asp:TemplateField HeaderText="Edit" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate>
<asp:ImageButton ID="imgBtnEditar" runat="server" ImageUrl="~/iconos/Image.png" CommandName="edit" ToolTip="Edit">
</asp:ImageButton>
</ItemTemplate>
<ItemStyle Height="8px"></ItemStyle>
</asp:TemplateField>
I am importing a column in datatable to my grid. Now I want navigate to a new page on selecting a cell in grid by fetching the selected value. I have tried this by including bound field in my grid like
<asp:GridView ID="GDV_1" runat="server" EnableModelValidation="true" AutoGenerateColumns="false" OnSelectedIndexChanged="GDV_1_SelectedIndexChanged" AutoGenerateSelectButton="false" DataKeyNames="SROID">
<Columns>
<asp:BoundField DataField="SRONameinEnglish" HtmlEncode="False" DataFormatString="<a target='_blank' href='Test.aspx?code={0}>ClickHere</a>" />
</Columns>
</asp:GridView>
Doing this way my requirement is achieved but the all cells are displaying Common text Click here instead of showing data from Database.
Please give your suggestion on how to get the value from database into cell and make it clickable. I don't want to use Select button. Please find my current output.
This is my current output I want my data from DB instead of ClickHere.
You can use TemplateField
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnk<%# Eval("SRONameinEnglish")%>"><%# Eval("SRONameinEnglish")%></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
and click of LinkButton put your code to navigate anywhere.
In your case you are binding boundfield with static a tag which have href attribute so your not able to change text on that boundfield from your database.To get your approach you should
use TemplateField and bind data with text attribute using eval keyword as below example.
Try it:
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("name") %>' />
</ItemTemplate>
</asp:TemplateField>
OR
you can also bind link with your hyperlink using NavigateUrl property of hyperlink as below example.
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:HyperLink id="HyperLink2" NavigateUrl='<%#Eval("YourUrl") %>' Text='<%#Eval("name") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateField>
I hope it will helpful to you.
Im working in ASP.net with C#, i need help to correct or have an approach to get what i need.
Im working with gridview, data select a set of data that will be used depending of its primarykey into another table.
On the runtime on client side, i need to collect on the onclick event, the sid column of each row and put it into a hidden field. However, the code below, is not working for me as the <%#eval("sid"); %>! is being read as a string, than the current row value.
What i need is the checkbox once clicked alert(5) instead of alert('<%#eval("sid"); %>!'); that is what is currently doing.
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server" ID="cbSelect" onclick="javascript:alert('<%#eval("sid"); %>!');"/>
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataTextField="nombre" NavigateUrl="http://www.google.com" HeaderText="direccion"/>
<asp:BoundField DataField="sid" HeaderText="sid" InsertVisible="False"
ReadOnly="True" SortExpression="sid" />
<asp:BoundField DataField="nombre_archivo" HeaderText="nombre_archivo"
SortExpression="nombre_archivo" />
</Columns>
If further information is needed, please ask what you need me to add to the question.
Try this, worked for me:
<asp:CheckBox runat="server" ID="cbSelect" onclick='<%# "javascript:alert(" + Eval("sid") + " );" %>'/>
I believe Eval is case-sensitive, and you don't need that semi-colon:
<%# Eval("sid") %>
Try changing your code to this. And your Eval() was actually eval() which is invalid.
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server"
ID="cbSelect"
onclientclick='<%#string.Format("javascript:alert('{0}');",Eval("sid"))%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataTextField="nombre"
NavigateUrl="http://www.google.com" HeaderText="direccion"/>
<asp:BoundField DataField="sid" HeaderText="sid" InsertVisible="False"
ReadOnly="True" SortExpression="sid" />
<asp:BoundField DataField="nombre_archivo" HeaderText="nombre_archivo"
SortExpression="nombre_archivo" />
</Columns>
Here is the code:
<asp:DataGrid id="dataGrid1" runat="server" OnItemDataBound="dataGrid1_ItemDataBound">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlFields="Valid,CouponCode"
DataTextField="Valid"
HeaderText="Enable / Disable"
DataNavigateUrlFormatString="?id={0}orgValue={1}" />
</Columns>
</asp:DataGrid>
In newer version of .net they got DataNavigateUrlFields, but in asp.net only have DataNavigateUrlField. (Ref: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.datanavigateurlfields(v=vs.80).aspx)
So, how can I pass two value into HyperLinkColumn? Thanks.
If you need to pass multiple parameters then convert that column to itemtemplate hyperlink column and then pass multiple parameters using navigateURL property. Like
<asp:datagrid id="dataGrid1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateColumn HeaderText="Order">
<ItemTemplate>
<asp:Hyperlink runat= "server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductName").tostring%>'
NavigateUrl='<%# "page2.aspx?Name=" & DataBinder.Eval (Container.DataItem,"ProductName").tostring & _
"&ProductID=" & DataBinder.Eval(Container.DataItem,"ProductID").tostring %>' ID="ProductName"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
You have to do something like that,Hope it works..