how to get row id on mouse rollover on gridview cell of rows

Posted by Sharadgupta2110 under ASP.NET on 10/27/2010 | Points: 10 | Views : 3163 | Status : [Member] | Replies : 7
Hello All,

I have one gridview fetching data from database and showing, now i want to get the particular rows id (which is not visible in gridview) on mouse rollover on particular cells of rows in gridview. please help me...
Thanks in advance...

Regards
Sharad Gupta

Sharad Gupta


Responses

Posted by: Lalji_mer on: 10/27/2010 [Member] Bronze | Points: 25

Up
0
Down
try this code sample

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", string.Format("alert('{0}');",e.Row.RowIndex));
}
}


LP MER

Sharadgupta2110, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sharadgupta2110 on: 10/27/2010 [Member] Starter | Points: 25

Up
0
Down
Thanks for giving quick response, this code will return the rows number like o, 1, 2 etc, but i want rows id which is in database but not visible in gridview..

This code is working fine giving row number but not id..

Thanks

Sharad Gupta

Sharadgupta2110, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 10/27/2010 [Member] Starter | Points: 25

Up
0
Down
You can keep the rowid of the database inside the hidden html div, write the onmouseover javascript function to show the div.

This will solve your problem.

Regards,
Raja, USA

Sharadgupta2110, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 1/22/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
hi Sharadgupta2110

u set ur gridview select Button TRUE . on SelectIndexChaning event write this code

protected void gv_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = gv.SelectedRow;
Label1.Text = row.Cells[0].Text;

}

Thanks & Regard's
Prabhakar

Best Regard's
Prabhakar

Sharadgupta2110, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/22/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Try this using a java script

<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input type="button" value="getIndex" onclick="getIndex(<%# Container.DataItemIndex %>);" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<script type="text/javascript">
function getIndex(index) {
alert(index);
}
</script>


Thanks
Karthik
www.f5Debug.net

Sharadgupta2110, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumarsudu on: 1/24/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Please assign the rowId in the DataKeyField of the Gridview
<asp:GridView ID="grdview1" datakeynames="RowId".........

then you write the below code in rowDataBound

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", string.Format("alert('{0}');",GridView1.DataKeys[e.Row.RowIndex].Value.ToString()));
}
}
Hope this helps you.

Thanks and Regards,
Kumar

Sharadgupta2110, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 1/24/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,,

Here step by step guide

http://csharpbits.notaclue.net/2008/08/customising-gridview-for-row-rollover.html

LP MER

Sharadgupta2110, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response