Hi All,
I am using GridView and binding the data using boundfield, ItemTemplete control binding. I want the value which is binding to each cell as a custom attribute to that cell to..
i.e final HTML would look like this
I think in row databound event I can add attribute using
cell.attribute.add("myattribute") =?
but how to get correct value which is being assigned to that cell?
Thanks and regards,
Tanmay.
Hi,
Instead of using a custom attribute, its better to use HiddenField
With in the same ItemTemplate, after checkbox control, use the hiddenfield and save your value in it.
Thats how u can access the cell related value from serverside or clientside.
hi Tanmay,
From what I understand you want to get data in attribute.you can try using this method.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string script = String.Format("GetdatakeyValue('{0}')", GridView1.DataKeys[e.Row.RowIndex].Value.ToString());
e.Row.Attributes.Add("onclick",script);
}
}
Please read the reference below for more information:
http://www.codeproject.com/Questions/510800/howplusiplusgetplusgridplusviewplusdatakeyplusvalu
Hi,
OnrOwDatabount(){
Dim chk As CheckBox
chk = e.Row.FindControl("CheckBox1")
chk .InputAttributes.Add("myattribute",
griedview1.DataKeys(e.Row.RowIndex).Item("ABCD"))
}
on any event
in foreach loop can get attributes
foreach(griedviewrow dr in datasete.tables[0].rows){
Dim chk As CheckBox
chk =dr.FindControl("CheckBox1")
string attribute=chk.InputAttributes("myattribute");
}
沒有留言:
張貼留言