DynamicallyPopulateGridView\Matrix

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gh

    DynamicallyPopulateGridView\Matrix

    I am using VS 2008. I have a SqlDataAdapter that returns the Names of
    the 50 states and a unique id for each state. I have a Grid View with
    6 columns defined as template fields, the markup is below. As I load
    each state name into a cell I check to see if there are active members
    in that state and put an image in the cell before the state name. Each
    state name is also a hyperlink I attach the unique id to. The grid view
    is 20 rows. When I get to row 20 then I will start at the top in row 0
    column 2.

    How can I get hold of the row\cell, to set the image url and name
    hyperlink? I have created html tables dynamically before and added the
    cells and rows at runtime, but the client would rather I use a html
    table or gridview with the rows and columns preset.

    TIA

    <asp:GridView ID="gvStates" runat="server" AutoGenerateCol umns="False"
    PageSize="20" ShowHeader="Fal se" Width="535px">
    <Columns>
    <asp:TemplateFi eld>
    <EditItemTempla te>
    <asp:TextBox ID="TextBox1"
    runat="server"> </asp:TextBox>
    </EditItemTemplat e>
    <ItemTemplate >
    <asp:Image ID="Image1" runat="server" />
    </ItemTemplate>
    </asp:TemplateFie ld>
    <asp:TemplateFi eld>
    <ItemTemplate >
    <asp:HyperLin k ID="HyperLink1 " runat="server"
    NavigateUrl="" Text=""></asp:HyperLink>
    </ItemTemplate>
    </asp:TemplateFie ld>
    <asp:TemplateFi eld>
    <EditItemTempla te>
    <asp:TextBox ID="TextBox2"
    runat="server"> </asp:TextBox>
    </EditItemTemplat e>
    <ItemTemplate >
    <asp:Image ID="Image2" runat="server" />
    </ItemTemplate>
    </asp:TemplateFie ld>
    <asp:TemplateFi eld>
    <ItemTemplate >
    <asp:HyperLin k ID="HyperLink2 " runat="server"
    NavigateUrl="" Text=""></asp:HyperLink>
    </ItemTemplate>
    </asp:TemplateFie ld>
    <asp:TemplateFi eld>
    <EditItemTempla te>
    <asp:TextBox ID="TextBox3"
    runat="server"> </asp:TextBox>
    </EditItemTemplat e>
    <ItemTemplate >
    <asp:Image ID="Image3" runat="server" />
    </ItemTemplate>
    </asp:TemplateFie ld>
    <asp:TemplateFi eld>
    <ItemTemplate >
    <asp:HyperLin k ID="HyperLink3 " runat="server"
    NavigateUrl="" Text=""></asp:HyperLink>
    </ItemTemplate>
    </asp:TemplateFie ld>
    </Columns>
    </asp:GridView>
  • Stan

    #2
    Re: DynamicallyPopu lateGridView\Ma trix

    On 25 Apr, 16:50, gh <g...@att.netwr ote:
    I am using VS 2008.  I have a SqlDataAdapter that returns the Names of
    the 50 states and a unique id for each state.   I have a Grid View with
    6 columns defined as template fields, the markup is below.  As I load
    each state name into a cell I check to see if there are active members
    in that state and put an image in the cell before the state name.  Each
    state name is also a hyperlink I attach the unique id to.  The grid view
    is 20 rows.  When I get to row 20 then I will start at the top in row 0
    column 2.
    >
    How can I get hold of the row\cell, to set the image url and name
    hyperlink?  I have created html tables dynamically before and added the
    cells and rows at runtime, but the client would rather I use a html
    table or gridview with the rows and columns preset.
    >
    TIA
    >
      <asp:GridView ID="gvStates" runat="server" AutoGenerateCol umns="False"
                 PageSize="20" ShowHeader="Fal se" Width="535px">
                 <Columns>
                     <asp:TemplateFi eld>
                         <EditItemTempla te>
                             <asp:TextBox ID="TextBox1"
    runat="server"> </asp:TextBox>
                         </EditItemTemplat e>
                         <ItemTemplate >
                             <asp:Image ID="Image1" runat="server" />
                         </ItemTemplate>
                     </asp:TemplateFie ld>
                     <asp:TemplateFi eld>
                         <ItemTemplate >
                             <asp:HyperLin k ID="HyperLink1 " runat="server"
    NavigateUrl="" Text=""></asp:HyperLink>
                         </ItemTemplate>
                     </asp:TemplateFie ld>
                     <asp:TemplateFi eld>
                         <EditItemTempla te>
                             <asp:TextBox ID="TextBox2"
    runat="server"> </asp:TextBox>
                         </EditItemTemplat e>
                         <ItemTemplate >
                             <asp:Image ID="Image2" runat="server" />
                         </ItemTemplate>
                     </asp:TemplateFie ld>
                     <asp:TemplateFi eld>
                         <ItemTemplate >
                             <asp:HyperLin k ID="HyperLink2 " runat="server"
    NavigateUrl="" Text=""></asp:HyperLink>
                         </ItemTemplate>
                     </asp:TemplateFie ld>
                     <asp:TemplateFi eld>
                         <EditItemTempla te>
                             <asp:TextBox ID="TextBox3"
    runat="server"> </asp:TextBox>
                         </EditItemTemplat e>
                         <ItemTemplate >
                             <asp:Image ID="Image3" runat="server" />
                         </ItemTemplate>
                     </asp:TemplateFie ld>
                     <asp:TemplateFi eld>
                         <ItemTemplate >
                             <asp:HyperLin k ID="HyperLink3 " runat="server"
    NavigateUrl="" Text=""></asp:HyperLink>
                         </ItemTemplate>
                     </asp:TemplateFie ld>
                 </Columns>
             </asp:GridView>
    Use the e parameter of the RowDataBound event handler to retrieve a
    DataRow as follows:

    DataRow drState = (DataRow)e.Row. DataItem;

    Then access the data values with drState["ColumnName "] etc

    Comment

    Working...