TransWikia.com

how to get grid id as string in c#

Stack Overflow Asked by dr.engg on December 30, 2020

I am trying to perform one operation by placing image in grid. Here I need to take id of two column from the grid, one is a hidden column and another is a normal column.

        <asp:LinkButton ID="Budgetid" runat="server" CssClass="EditLink" CommandName="EDIT" TabIndex="6"
            Text='<%#Eval("Budget_id") %>'></asp:LinkButton>
        <asp:HiddenField ID="hf_Bgid" runat="server" Value='<%#Eval("Budget_id") %>' />
    </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Row_Status" Visible="false" HeaderStyle-CssClass="grid_header_text">
    <ItemStyle />
    <ItemTemplate>
        <asp:Label ID="lblRowStatus" runat="server" Visible="false" CssClass="OperationFont" Text='<%#Eval("Row_Status") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budget code" SortExpression="Budget_Code" HeaderStyle-ForeColor="Wheat" HeaderStyle-CssClass="grid_header_text">
    <ItemStyle Wrap="false" HorizontalAlign="center" />
    <ItemTemplate>
        <asp:Label ID="BCode" runat="server" CssClass="OperationFont" Text='<%#Eval("Budget_code") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

I have already got one value form the grid using

string strClid = ((HiddenField)row.FindControl("hf_Bgid")).Value.ToString();

Now I need to get the value of BCode as string like the hf_bgid.

I tried like this:

string strbudcode =  ((TemplateField)row.FindControl("BCode")).Value.ToString();
string strbudcode = ((Label)gvBudget.FindControl("Budget_code")).Text;

but strbudcode value always becomes null.

One Answer

You need to look up the value in your rowDataBound Event, you can just use labels for both but mark the column visible =false so it wont show on the page but you will have access to it from the code behind

  if(e.Row.RowType == DataControlRowType.DataRow)
  {
     string strbudcode = ((Label)e.Row.FindControl("BCode")).Text;
  }

Answered by JobesK on December 30, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP