GridView samples

satya - Thursday, May 24, 2007 10:28:48 PM

A template column


<asp:GridView ID="wellGrid" AutoGenerateColumns="False" runat="server" 
   Width="100%" CssClass="ReportTable" HeaderStyle-CssClass="ReportTableHeaderRow">
   <Columns>
         <asp:TemplateField HeaderText="wellname" ItemStyle-Width="20%">
            <ItemTemplate>
               <asp:HyperLink ID="WellNameHyperLinkItemLabel" 
               Text='<%# getValue(Container.DataItem,"well_nm") %>'
               NavigateUrl='<%# String.Format("/test-website/well.aspx?wellid={0}"
			        ,getValue(Container.DataItem,"well_loc_id"))%>'
               runat="server" />
            </ItemTemplate>
         </asp:TemplateField>
   </Columns>
</asp:GridView>

satya - Thursday, May 24, 2007 10:34:14 PM

A bound field


<asp:GridView runat="server" ID="queryGridControl" 
AutoGenerateColumns="false" Width="100%">
<Columns>
    <asp:BoundField DataField="query_name" DataFormatString="{0}" />
</Columns>
</asp:GridView>

satya - Wednesday, June 06, 2007 9:25:32 AM

using an onrowcommand


<asp:GridView runat="server" ID="queryGridControl" 
     OnRowCommand="OnRowCommand_ShowQuery"
      DataKeyNames = "query_id"
    AutoGenerateColumns="false" Width="100%">
<Columns>
    <asp:ButtonField  
        ButtonType="Link" 
        DataTextField="query_name" 
        DataTextFormatString="{0}" 
        text="Saved Queries" 
        CommandName="showQueryCommand" />
</Columns>
</asp:GridView>