Problem when viewing data from a grid within the code behind

0

In a GridView I'm trying to get the data for a row where checkbox == true .

I can get the value of the checkbox, but I can not 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>
    
asked by anonymous 13.07.2015 / 16:36

1 answer

0

From what I understand, you just need to show the ID and Name in your gridview. You can change to BoundField, which will show you the text and when you try to access the code behind it will work normally. Change your Id and Name code snippet to the snippet below:

<asp:BoundField DataField="ID" HeaderText="Id" ItemStyle-HorizontalAlign="Center" />

<asp:BoundField DataField="NOME" HeaderText="Protocolo" ItemStyle-HorizontalAlign="Center" />
    
29.06.2018 / 14:52