2
Answers

gridview checkbox checked showing false

Sivakumar

Sivakumar

8y
295
1
Hi ,
This is my Gridview :
<asp:GridView ID="pendingOrders" ClientIDMode="Static" CssClass="table table_heading_bg table-striped table-bordered table-hover dataTable no-footer" runat="server" EmptyDataText="No Records Found" AutoGenerateColumns="false" AllowPaging="true"
PageSize="20" OnRowCommand="pendingOrders_RowCommand" OnRowDataBound="pendingOrders_OnDataBound" PagerStyle-CssClass="pagination_grid" OnSelectedIndexChanged="OnSelectedIndexChanged">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkAllSelect" runat="server" onclick="CheckAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="S.No">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="OrderID" ItemStyle-CssClass="hide" HeaderStyle-CssClass="hide" HeaderText="OrderID" />
<asp:BoundField DataField="UserID" ItemStyle-CssClass="hide" HeaderStyle-CssClass="hide" HeaderText="UserID" />
<asp:BoundField DataField="TemplateID" ItemStyle-CssClass="hide" HeaderStyle-CssClass="hide" HeaderText="Template ID" />
<asp:TemplateField HeaderText="User">
<ItemTemplate>
<asp:LinkButton ID="lnkUser" runat="server" Text='<%# Eval("UserName")%>' OnClick="UserDetails"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<%--<asp:ButtonField HeaderText="Selected Template" DataTextField="TemplateName" />--%>
<asp:TemplateField HeaderText="Selected Template">
<ItemTemplate>
<a onclick="ShowSelectedImage('<%# DataBinder.Eval(Container.DataItem,"TemplateID") %>')"><%# DataBinder.Eval(Container.DataItem,"TemplateName") %></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Personalized Message">
<ItemTemplate>
<a onclick="ShowCustomerMessage('<%# Eval("Message").ToString().Replace('\"',' ') %>')"><%# DataBinder.Eval(Container.DataItem,"Message").ToString().Length<=50 ? Eval("Message") : Eval("Message").ToString().Substring(0, 50) %></a>
<%--<asp:LinkButton ID="lblDesc" OnClientClick='<%# "showMsg(\""+ Eval("Message")+"\");return false;" %>' runat="server" Text='<%# Eval("Message").ToString().Length <= 50 ? Eval("Message") : Eval("Message").ToString().Substring(0, 50) %>' ToolTip='<%# Eval("Message") %>'></asp:LinkButton>--%>
<%--<asp:LinkButton ID="btnreadMore" runat="server" Text="Read More" Visible='<%# SetVisibility(Eval("Message"), 50) %>' OnClick="btnreadMore_Click" CssClass="NoUnderLine"></asp:LinkButton>--%>
<asp:Label ID="lblExtra" runat="server" ToolTip='<%# Eval("Message").ToString().Length <= 50 ? Eval("Message") : Eval("Message").ToString().Substring(0, 50) %>' Text='<%# Eval("Message") %>' Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:BoundField DataField="Message" HeaderText="Message" />--%>
<asp:ButtonField Text="Show Addresses" HeaderText="Selected Addresses" CommandName="Select" ItemStyle-Width="150" />
<%-- <asp:ButtonField Text="Complete" HeaderText="Status" CommandName="confirm" ItemStyle-Width="150" />--%>
</Columns>
<PagerSettings PageButtonCount="20" />
<PagerStyle CssClass="pagination_grid"></PagerStyle>
</asp:GridView>
Screenshot :
 
 
This is C# code :
 
  StringCollection idCollection = new StringCollection();
string strID = string.Empty;
foreach (GridViewRow gvrow in pendingOrders.Rows)
{

CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");
if (chk != null & chk.Checked)
{
strID = gvrow.Cells[1].Text;
idCollection.Add(strID);

}
}
}
 
But here showing checkbox checked is false 
 
Please give me a help
 
Thanks.
 
 

Answers (2)