Heklo there.
I can't get a hidden field value from a gridview using c# and asp.net
I don't have error but the value of the hidden field is not sent and validated in GridView1_RowDataBound.
My code below, can you help me?
<asp:TemplateField
HeaderText="S"
ItemStyle-CssClass="ddl_Class_new"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server"
ImageUrl='<%#(Eval("S").ToString().Contains("OK") ? "/aspnet/img/bullett/forestbul.gif" : "/aspnet/img/bullett/redbul.gif")%>'
ToolTip='<%#(Eval("S").ToString().Contains("OK") ? "OK" : "KO")%>'
Enabled="false" />
<asp:HiddenField ID="hddblink" runat="server" Value='<%#Eval("S")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:CheckBox ID="chkBxHeader"
AutoPostBack="true" OnCheckedChanged="chkBxHeader_CheckedChanged" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<div>
<asp:CheckBox ID="chkRow" runat="server" Enabled="false" />
</div>
</ItemTemplate>
</asp:TemplateField>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HiddenField BlinkTask = e.Row.FindControl("hddblink") as HiddenField;
CheckBox cbTrue = (CheckBox)e.Row.FindControl("chkRow");
string S = BlinkTask.Value.ToString();
if (S.ToString() == "OK")
{
cbTrue.Checked = true;
}
else
{
cbTrue.Checked = false;
}
}
}
catch (Exception ex)
{
Console.WriteLine("Skipped exception! " + ex);
}
}