I have a dropdown and a gridview. Depending on the value selected in the dropdown, I want to update the NaviagetURL for the hyperlink specified in 1st column of the gridview. So I am using onRowDataBound function to update the hyperlink's navigateurl dynamically. And, I am trying to retrieve value of first column "ID" to use it as the query string inside the OnRowDataBound function but I am not able to get this working.
When I click on the hyperlink in the first column, the query string doesn't have any value assigned to the variable ID. So, the url just resolves to http://localhost/JobCosting/EditSavedTicket.aspx?ID=
What is expected is, the url which opens on clicking the hyperlink should have the value specified in 1st column assigned to the variable ID in the query string. If I use e.Row.Cells[1].Text or e.Row.Cells[2].Text, the column value is being retrieved correctly, but I need the value in column zero which is not getting retrieved. When I check the length of the string id which is e.Row.Cells[0].Text, it is zero
GridView:
<asp:GridView ID="GridView2" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="Saved_Work" OnRowDataBound="update_url"
Style="float: left; font-size: small; position: relative;
width: 82%; position: relative; top: -10px; height: 40px; font-size: small; text-align: left;
left: 30px;" align="left">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:HyperLink ID="Continue_SavedWork" runat="server" NavigateUrl='<%# Eval("ID", "~/EditSavedJob.aspx?ID={0}") %>'
Text='<%# Eval("ID") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserID" HeaderText="User" SortExpression="UserID" />
<asp:BoundField DataField="Date_Created" HeaderText="Last_Updated_On" SortExpression="Date_Created" />
</Columns>
</asp:GridView>
Code behind:
protected void update_url(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//string NavigateUrl="<%# Eval('ID', 'EditSavedTicket.aspx?ID={0}) %>";
string id = e.Row.Cells[0].Text;
HyperLink hp = (HyperLink)e.Row.FindControl("Continue_SavedWork");
if (SavedWorkDD.SelectedValue.ToString() == "Tickets")
hp.NavigateUrl = string.Format("EditSavedTicket.aspx?ID={0}", id);
}
}