Click here to Skip to main content
15,898,795 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more:
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.NET
<asp:TemplateField HeaderText="FileName" ItemStyle-HorizontalAlign="Center">  <itemtemplate> <asp:LinkButton ID="btn"  runat="server" CommandName="Click"/> </itemtemplate>
aspx.cs - below code i have written on rowdatabound
C#
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
Posted
Updated 9-Oct-12 1:48am
v3

Inside row databound, get the column object by the following code

Label TestLabel = (Label)e.Row.FindControl("MyLabel");
   TestLabel.Text= "Hello";


Then assign any property value to it.
 
Share this answer
 
Write in gridview row command event args

here the command name is click

declare string value=string.empty;

if(e.commnadName=="click")
{

//if you put the text box find the text box
Gridviewrow row= gridview1.rows[2] as gridviewrow

textbox txtid=row.fincontrol("txtid in item template");

value=txtid.Text; // Here you can read the value in the textbox ;

}


inform me, you get it or not
 
Share this answer
 
Hi For this you need to find the control of the column's cell and then you need to change the value.

Hope this will help you.
 
Share this answer
 
v2
Use this:

http://msdn.microsoft.com/en-us/library/bda9bbfx%28v=vs.71%29.aspx[^]

ASP.NET
<asp:LinkButton ID="btn"  runat="server" CommandName="Click" Text='<%# Eval("dataSourcePropertyName") %>' />
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900