
I have a GridView:
On Button_Click
I want the first column of my GridView with the items of ListBox1 and 2nd column with the EDIT link and from 3rd column on wards I want the headers as the items of ListBox2.
So far I am able to achieve EDIT link in the 2nd column and from 3rd column on wards the headers of the GridView with ListBox2 items.
Now I want ListBox1 items as the first column of my GridView. I have attached an image with show what exactly I want and what I have achieved so far.
Kindly help me on. Thank you.
The .cs code I have designed is:
DataTable dt = new DataTable();
DataRow rw = default(DataRow);
for (int i = 0; i < ListBox3.Items.Count; i++)
{ dt.Columns.Add(ListBox3.Items[i].ToString(),System.Type.GetType("System.String"));
}
for (int j = 0; j < count; j++)
{
rw = dt.NewRow();
for (int i = 0; i < ListBox3.Items.Count; i++)
{
rw[ListBox3.Items[i].ToString()] = " ";
}
dt.Rows.Add(rw);
}
GridView2.DataSource = dt;
GridView2.DataBind();
The asp code for GridView is :
<Columns>
<asp:TemplateField HeaderText="Locations">
<ItemTemplate>
<asp:Label ID="Lab1" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Columns>
First create a event of your
gridview_RowDataBoundand change value of your label