Click here to Skip to main content
15,891,723 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I need to split the all the records from the database into two columns in a table inside the grid view


My database looks like this
Name profession company
---- ---------- -------
AA Engg AAA
BB design BBB
cc coding CCC

and i need the output as
[img]AA                 [img]BB
    engg                    design
    AAA                     BBB

[img]CC
     coding
     CCC

like a table in a grid view.
My code is as follows
ASP.NET
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"  ForeColor="#333333" GridLines="None" Height="1px" ShowHeader="False" Width="206px">
            <rowstyle backcolor="White" bordercolor="Red" />
            <columns>           
            <asp:TemplateField AccessibleHeaderText="User Details" HeaderText="User Details">
<itemtemplate>
<table cellpadding="4" cellspacing="0" style="border-style:solid; border-width:thin; border-color:Black">
<tr style=" background:AliceBlue">
<td>
<asp:Image CssClass="img" ID="Image1" ImageUrl="~/Images/images.jpg" ImageAlign="Left" Width="50" Height="50" runat="server" BorderWidth="1" BorderColor="Gainsboro" />
</td>
<td align="left">                
<asp:Label  Font-Size="14" ForeColor="RoyalBlue" Font-Underline="true" ID="Label1" Width="150px" runat="server" Text='<%# Bind("name") %>'><br />
<asp:Label Font-Size="12" ID="Label2" Width="150px" runat="server"  Text='<%# Bind("profession") %>'><br />
<asp:Label Font-Size="12" ID="Label3" runat="server" Width="150px"  Text='<%# Bind("company") %>'><br />
</td>
</tr>           
</table>
            </itemtemplate>

and the code behind file will be

C#
protected void Page_Load(object sender, EventArgs e)
   {
       populatefield();
   }

   protected void populatefield()
   {

       connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

       connection.Open();
       command = new SqlCommand("select * from Grid_tbl", connection);
       dataAdapter = new SqlDataAdapter(command);
       table = new DataTable();
       dataAdapter.Fill(table);
       GridView1.DataSource = table;
       GridView1.DataBind();
       connection.Close();

   }

and give me a solution for this problem
The problem is that i need the output which has to show "each record(has multiple columns) from the database in to a single cell in the table(which has exactly 2 cells)"

for example see this link

Example for my problem
Posted
Updated 6-Mar-13 6:20am
v7
Comments
Richard C Bishop 6-Mar-13 10:46am    
So what is your problem?
Manikandan Sekar 6-Mar-13 10:51am    
The problem is that i need the output as mentioned above it has to show each record(has multiple columns) in a single cell in table(which has exactly 2 cells)
joshrduncan2012 6-Mar-13 10:55am    
I second Rich's comment and add a follow-up. Do you want to hire someeone to write that for you?
Richard C Bishop 6-Mar-13 11:03am    
Well, a GridView shows rows of data that were queried from a database. The type of functionality you are wanting is found in a listview. Try using that instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900