DynamicallyPopulateGridView\Matrix

G

gh

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" AutoGenerateColumns="False"
PageSize="20" ShowHeader="False" Width="535px">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="" Text=""></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Image ID="Image2" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="" Text=""></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox3"
runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Image ID="Image3" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink3" runat="server"
NavigateUrl="" Text=""></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
 
S

Stan

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" AutoGenerateColumns="False"
             PageSize="20" ShowHeader="False" Width="535px">
             <Columns>
                 <asp:TemplateField>
                     <EditItemTemplate>
                         <asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
                     </EditItemTemplate>
                     <ItemTemplate>
                         <asp:Image ID="Image1" runat="server" />
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField>
                     <ItemTemplate>
                         <asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="" Text=""></asp:HyperLink>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField>
                     <EditItemTemplate>
                         <asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>
                     </EditItemTemplate>
                     <ItemTemplate>
                         <asp:Image ID="Image2" runat="server" />
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField>
                     <ItemTemplate>
                         <asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="" Text=""></asp:HyperLink>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField>
                     <EditItemTemplate>
                         <asp:TextBox ID="TextBox3"
runat="server"></asp:TextBox>
                     </EditItemTemplate>
                     <ItemTemplate>
                         <asp:Image ID="Image3" runat="server" />
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField>
                     <ItemTemplate>
                         <asp:HyperLink ID="HyperLink3" runat="server"
NavigateUrl="" Text=""></asp:HyperLink>
                     </ItemTemplate>
                 </asp:TemplateField>
             </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
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top