Sunday, March 11, 2012

Value from TemplateField in GridView

Did you ever get a solution for this?

I'm trying to get a value from a TemplateField column and am at a total loss.

thanks


Hi,
If you want to retrive the value of the controls in the Template, you can have a look at following code. 
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e){// Retrieve rowGridViewRow gvr = GridView1.Rows[e.NewEditIndex];// Retrieve controlsTextBox txtProductID = gvr.FindControl("txtProductID")as TextBox;if (txtProductID !=null){Label1.Text = txtProductID.Text;}}
 
For the second question,

I Suppose, You can use RowIndex Property to achive this task. Please Have a look at the following example....

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.DataItemIndex == -1)
return;

HyperLink lnk = (HyperLink) e.Row.FindControl("hlnkClient")

lnk.Attributes.Add("onclick",
this.GetPostBackClientEvent("Select$" + e.Row.RowIndex.ToString()));
e.Row.Attributes.Add("onMouseOver",
"this.style.cursor='hand';");
}

Javascript:

function GetPostBackClientEvent(RowIndex){

alert(RowIndex);

}

No comments:

Post a Comment