Thursday, December 23, 2004

How to make DataGrid HyperLink Client And Server Side

Client Side HyperLink
1)  Write this in side datagrid tag
<asp:HyperLinkColumn HeaderText="Column Header" DataNavigateUrlField="Column Field name" DataNavigateUrlFormatString="DefineSourceType.aspx?dm_id={0}" DataTextField="Define" Target="_new" />
Column Header       : Anything you want to in header
Column Field name : The datafield column as you want as value
Define                      : The datatable field as you want as column text
{0}                            :  Indicating your column no as in the query start from 0
2) Now in code behind
 Dim dataset As New DataSet()
 Dim DataTable As New DataTable()

 DataGrid1.DataSource = dataset
Server Side HyperLink
1) write this tag in the datagrid tag
    <asp:TemplateColumn HeaderText="Source type" Visible="True">
            <HeaderStyle CssClass="text_9_b"></HeaderStyle>
            <ItemStyle CssClass="text_9"></ItemStyle>
             <asp:HyperLink ID="hlnSourceType" Runat="server"></asp:HyperLink>
2) got to the code behind and write in the "Datagrid1_Itembound()" event
   If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
        Dim hlnSourceType As HyperLink = CType(e.Item.FindControl("hlnSourceType"), HyperLink)
        hlnSourceType.Text = CType(e.Item.DataItem, RxLogic.Location).SourceType.ToString()
        hlnSourceType.NavigateUrl = "DefineSourcetype.aspx?dm_id=" + iDMID.ToString()
   End If

     iDMID : the value as you want in the query string



No comments: