Text property is coming blank in gridview cell!

2

I'm using a gridview and I need to get the contents of the line to which the checkbox is checked==true . I can get the status of checkbox , but the text property of the cell is coming in white.

Follow the code below:

protected void btnEnviar_Click(object sender, EventArgs e)
{

    int i = 0;
    while (i < gvwNot.Rows.Count)
    {
        GridViewRow row = gvwNot.Rows[i];
        CheckBox isChecked = (CheckBox)row.FindControl("chkSelect");

        if (isChecked.Checked == true)
        {
            string str = gvwNot.Rows[i].Cells[1].Text;
            //Fazer um update na PRT alterando os campos DATA RETORNO e Data Limite
            //PRT_DT_LM_PGT
            //nrc_dt_sta
        }
        i++;
    }

//Impressão de intimações realizada com sucesso.

}

ASP.NET

<asp:GridView ID="gvwNot" runat="server" AutoGenerateColumns="False" DataKeyNames="COD" 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="Cod." >
            <ItemTemplate><%#Eval("COD") %>    </ItemTemplate>
        </asp:TemplateField>

    </Columns>
    <PagerSettings Mode="NextPrevious" NextPageText="Próximo" PreviousPageText="Anterior" />
</asp:GridView>
    
asked by anonymous 10.07.2015 / 21:32

1 answer

1

Why do not you try to use a TextBox or BoundField:

 <Columns>
    <asp:TemplateField HeaderText="Cod." >
        <ItemTemplate><asp:TextBox id="txtCod" Text='<%#Eval("COD") %>' /> </ItemTemplate>
    </asp:TemplateField>
</Columns>

 int i = 0;
while (i < gvwNot.Rows.Count)
{
    GridViewRow row = gvwNot.Rows[i];
    CheckBox isChecked = (CheckBox)row.FindControl("chkSelect");

    if (isChecked.Checked == true)
    {
        string str = ((TextBox) gvwNot.Rows[i].FindControl("txtCod")).Text;
        //Fazer um update na PRT alterando os campos DATA RETORNO e Data Limite
        //PRT_DT_LM_PGT
        //nrc_dt_sta
    }
    i++;
}

---------------------------
 <Columns>
 <asp:BoundField DataField="COD" />
</Columns>

 if (isChecked.Checked == true)
    {
        string str = gvwNot.Rows[i].Cells[1].Text;
        //Fazer um update na PRT alterando os campos DATA RETORNO e Data Limite
        //PRT_DT_LM_PGT
        //nrc_dt_sta
    }
    i++;
    
22.03.2016 / 18:07