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: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
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