ASP.NET 1.1 DataGrid Question

G

Guest

Hello,

I have a datagrid with linkbutton on the first column which shows a number
Id to select a particular record. Currently the users have to click on the
number (column1) to select. Instead, I want to change this behaviour to
rowclick. I mean the users can click on any columns of that row to select a
particular record.

Remember I got to use LinkButton on the first column always.

TIA,
Holy
 
E

Eliyahu Goldin

Handle ItemDataBound event like this:

' Visual Basic
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemDataBound
Dim itemType As ListItemType = e.Item.ItemType
If ((itemType = ListItemType.Pager) Or _
(itemType = ListItemType.Header) Or _
(itemType = ListItemType.Footer)) Then
Return
Else
Dim button As LinkButton = _
CType(e.Item.Cells(0).Controls(0), LinkButton)
e.Item.Attributes("onclick") = _
Page.GetPostBackClientHyperlink(button, "")
End If
End Sub

// C#
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if ((itemType == ListItemType.Pager) ||
(itemType == ListItemType.Header) ||
(itemType == ListItemType.Footer))
{
return;
}
LinkButton button = (LinkButton)e.Item.Cells[0].Controls[0];
e.Item.Attributes["onclick"] =
Page.GetPostBackClientHyperlink(button, "");



}
 
G

Guest

Thank you. It works fine.

Eliyahu Goldin said:
Handle ItemDataBound event like this:

' Visual Basic
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemDataBound
Dim itemType As ListItemType = e.Item.ItemType
If ((itemType = ListItemType.Pager) Or _
(itemType = ListItemType.Header) Or _
(itemType = ListItemType.Footer)) Then
Return
Else
Dim button As LinkButton = _
CType(e.Item.Cells(0).Controls(0), LinkButton)
e.Item.Attributes("onclick") = _
Page.GetPostBackClientHyperlink(button, "")
End If
End Sub

// C#
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if ((itemType == ListItemType.Pager) ||
(itemType == ListItemType.Header) ||
(itemType == ListItemType.Footer))
{
return;
}
LinkButton button = (LinkButton)e.Item.Cells[0].Controls[0];
e.Item.Attributes["onclick"] =
Page.GetPostBackClientHyperlink(button, "");



}

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

Holysmoke said:
Hello,

I have a datagrid with linkbutton on the first column which shows a number
Id to select a particular record. Currently the users have to click on the
number (column1) to select. Instead, I want to change this behaviour to
rowclick. I mean the users can click on any columns of that row to select
a
particular record.

Remember I got to use LinkButton on the first column always.

TIA,
Holy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top