0
On a Gridview I’m trying to get the data referring to a line where the checkbox == true
.
I can get the value of the checkbox, but I can’t get the other values for the line.
while (i < gvwNot.Rows.Count)
{
GridViewRow row = gvwNot.Rows[i];
CheckBox isChecked = (CheckBox)row.FindControl("chkSelect");
//TextBox id = (TextBox)row.FindControl("ID");
//TextBox nome = (TextBox)row.FindControl("NOME");
if (isChecked.Checked == true)
{
string id = gvwNot.Rows[i].Cells[1].Text;
string nome = gvwNot.Rows[i].Cells[3].Text;
qry = sb.ToString();
qtd = qtd + 1;
}
i++;
}
<asp:GridView ID="gvwNot" runat="server"
AutoGenerateColumns="False"
DataKeyNames="Id"
AllowPaging="True"
AllowSorting="true"
PageSize="10"
CssClass="table table-bordered table-hover table-striped" >
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<input id="chkAll" onclick="javascript: SelecionaTodosChecks(this);" runat="server" type="checkbox" />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Id">
<ItemTemplate><%#Eval("ID") %> </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Protocolo">
<ItemTemplate><%#Eval("NOME") %> </ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings Mode="NextPrevious" NextPageText="Próximo" PreviousPageText="Anterior" />
</asp:GridView>
You speak the ID and the name?
– Marconi
@Marconi Yes, in code behide, it appears empty.
– Germano Sampaio
Is called some event from some button to run this code?
– Marconi
yes, that’s inside the Onclick button, where tb have an Onclientclick with a Javascript validation where it checks if the field was typed.
– Germano Sampaio
Got it, your button is inside the grid or outside?
– Marconi
Out of the gridview.
– Germano Sampaio
Have a look here. There’s even a demo. http://www.aspsnippets.com/Articles/GridView-with-CheckBox-Get-Selected-Rows-ASPNet.aspx
– Marconi
Let’s go continue this discussion in chat.
– Germano Sampaio