I am facing a problem in grid view, basically what i am trying to achieve is below:
I have a grid view in which my first column is a link button, i have to put a condition where value from my 2nd column is taken and is input to a c# method for poulating a value which i need to assign into my first column.
I am trying below code however when i view my grid its showing 1st columns value as blank.
Aspx page:
<asp:TemplateField HeaderText="FileName" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID="btn" runat="server" CommandName="Click"/>
</ItemTemplate>
</asp:TemplateField>
aspx.cs
if (e.Row.RowType == DataControlRowType.DataRow)
{
int EmpiD = Int32.Parse(e.Row.Cells[2].Text);
DataSet EmpIDDs = GetEMP.getValue(EmpiD);
DataRow EmpRow = EmpIDDs.Tables[0].Rows[0];
e.Row.Cells[0].Text = EmpRow[3].ToString();
}
Please help me if you have any solution
You say that the
LinkButtonis in the firstTemplateField, then you cannot set theTextproperty of the cell. You need to useFindControlto get a reference to yourLinkButton.Assuming that the rest of your code is correct, for example that the third column is a
BoundFieldand contains an integer so thate.Row.Cells[2]works.I’m not sure if you’re familiar with the debugger.
Debugging-Tutorial: http://www.dotnetperls.com/debugging