Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: DataGrid Control with HyperLinkColumn?


Message #1 by Leena Natekar <paradise_flycatcher@y...> on Tue, 19 Jun 2001 03:48:25 -0700 (PDT)
Dear Leena,


There is two ways to access the data from the row :

1- using an HyperLinkColumn

Try to attach a command to your HyperLinkColumn by adding the 
attribute:

CommandName=3D"details"

Then attach an event to your DataGrid by adding the attribute:

OnItemCommand=3D"doItemCmd"

Add the doItemCmd() procedure in your code :

protected void doItemCmd (object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
       // Get the index of the selected ListItem with e.Item.ItemIndex
       //  and so get the full ListItem with
       ListItem    mySelectedListItem =3D 
myDataGrid.Items[e.Item.ItemIndex];

      // OR
      // DataGrid    myDG =3D (DataGrid) source;
     //  ListItem    mySelectedListItem =3D 
myDG.Items[e.Item.ItemIndex];
}

2- For my part, I usually use an itemtemplate column with a 
HyperLinkButton
control inside, and set its CommandName attribute to doItemCmd. Then I 
use
the code above.


| Mathieu Clerte
| DBA & Development , MCP
| E-mail: mathieuc@i...

| Statistics Institute of French Polynesia (ISPF)
| mail: BP 395 Papeete - Tahiti  -  French Polynesia  98713
| tel: (689) 543 232
| fax: (689) 427 252
| email: ispf@i...
| web: < http://www.ispf.pf <http://www.ispf.pf> >




-----Message d'origine-----
De : ASPX_Professional digest [ mailto:aspx_professional@p...
<mailto:aspx_professional@p...> ]
Envoy=E9 : mardi 19 juin 2001 13:00
=C0 : aspx_professional digest recipients
Objet : aspx_professional digest: June 19, 2001


ASPX_PROFESSIONAL Digest for Tuesday, June 19, 2001.

1. 

----------------------------------------------------------------------

Subject: DataGrid Control with HyperLinkColumn?
From: Leena Natekar <paradise_flycatcher@y...>
Date: Tue, 19 Jun 2001 03:48:25 -0700 (PDT)
X-Message-Number: 1

Hi,
I am using datagrid to display HyperLinkColumns
When a link in the datagrid is clicked I need to get
the row of the dataGrid. Something like datagrids
SelectedItem. Then I can access the data from the row
(which i require for further processing).

Problem : How to catch the event of the link getting
clicked.

Can anybody help me with the same?

<asp:DataGrid id=3D"MyDataGrid" runat=3D"server"
         BorderWidth=3D"0"
         GridLines=3D"none"
         CellPadding=3D"3"
         CellSpacing=3D"0"
         Font-Name=3D"Verdana"
         Font-Size=3D"8pt"
         HeaderStyle-BackColor=3D"#FFCC00"
         AutoGenerateColumns=3D"false"
         OnPageIndexChanged=3D"Grid_Change"
      >
         <property name=3D"Columns">
            <asp:HyperLinkColumn
               HeaderText=3D"Search results"
               DataNavigateUrlField=3D"LinkValue"
               DataTextField=3D"DataValue"
               Target=3D"main"
            />

         </property>




---

END OF DIGES

  Return to Index