Text property is empty in the gridview cell!

Asked

Viewed 41 times

2

I’m using a gridview and I need to get the content of the line the checkbox is on checked==true. I can catch the state of checkbox, but the text property of the cell is coming in white.

Follow the code:

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>

1 answer

1


Why don’t you try using 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++;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.