Datagrid item
-
Hi guys, i have a datagrid, i would like to get the value of one column when user clicks on that row(item) so that i can show the details of that row(item) on the next page. I have tried the below and am not so sure how to proceed:
protected void available_ItemDataBound(object sender, DataGridItemEventArgs e)
{
//string striD;
foreach(DataGridColumn col in available.Columns)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
//striD = available.DataKeys[e.Item.ItemIndex].ToString();
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#F9F9F9' this.style.cursor='pointer';");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff';this.style.cursor='pointer';");} }
}
Does anyone know how i can manage to get the value of one column in tha row that has been clicked? Please help me :doh: Regards MS
-
Hi guys, i have a datagrid, i would like to get the value of one column when user clicks on that row(item) so that i can show the details of that row(item) on the next page. I have tried the below and am not so sure how to proceed:
protected void available_ItemDataBound(object sender, DataGridItemEventArgs e)
{
//string striD;
foreach(DataGridColumn col in available.Columns)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
//striD = available.DataKeys[e.Item.ItemIndex].ToString();
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#F9F9F9' this.style.cursor='pointer';");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff';this.style.cursor='pointer';");} }
}
Does anyone know how i can manage to get the value of one column in tha row that has been clicked? Please help me :doh: Regards MS
Assuming your DataGrid is bound to a DataView with a unique ID value for each row, include a Hypelink in your DataGrid columns - say hypDetails, maybe within a template column - then you can put in your ItemDatBound code:
DataRow dr = e.Item.DataItem.Row;
HyperLink hypDetails = CType(e.Item.FindControl("hypDetails"), HyperLink);
hypDetails.NavigateUrl = "details.aspx?id=" & CStr(dr("ID"));This will pass the ID value of that row as a parameter to the next page (details.aspx)
-
Assuming your DataGrid is bound to a DataView with a unique ID value for each row, include a Hypelink in your DataGrid columns - say hypDetails, maybe within a template column - then you can put in your ItemDatBound code:
DataRow dr = e.Item.DataItem.Row;
HyperLink hypDetails = CType(e.Item.FindControl("hypDetails"), HyperLink);
hypDetails.NavigateUrl = "details.aspx?id=" & CStr(dr("ID"));This will pass the ID value of that row as a parameter to the next page (details.aspx)
Thanks alot man, i will give it a try just now.... but unfortunatly 'CType' does not exist in C# only VB...is there an alternative to this? :doh: Regards, MS
-
Thanks alot man, i will give it a try just now.... but unfortunatly 'CType' does not exist in C# only VB...is there an alternative to this? :doh: Regards, MS
OMG I've been outed! ;-) I'm sure a little Googling will sort you out...
-
Thanks alot man, i will give it a try just now.... but unfortunatly 'CType' does not exist in C# only VB...is there an alternative to this? :doh: Regards, MS