Hi,
here is my code to create the checkboxes in gridview dynamially. Now i want to read the checked items from every row by clicking on link button created dynamically in the last column of every row........
code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class timetable : System.Web.UI.Page
{
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
dt.Columns.Add("Classes");
foreach (ListItem li in chklst_subjs.Items)
{
if (li.Selected)
{
dt.Columns.Add(li.Text);
}
}
dt.Columns.Add("Select Teachers");
int n = Convert.ToInt32(tb_clrms.Text);
for (int i = 1; i <= n; i++)
{
dt.Rows.Add(i);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
int rows = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int rowscount = Convert.ToInt32(GridView1.Rows.Count);
int colscount = e.Row.Cells.Count;
int col = Convert.ToInt32(dt.Columns.Count)-1;
if (rowscount != 0)
{
foreach (DataColumn dc in dt.Columns)
{
col = col - 1;
if (col > 0)
{
CheckBox chk = new CheckBox();
chk.ID = "chk" + rows;
GridView1.Rows[rows].Cells[col].Controls.Add(chk);
LinkButton lb = new LinkButton();
lb.ID = "lb" + rows;
int n=Convert.ToInt32(dt.Columns.Count) - 1;
GridView1.Rows[rows].Cells[n].Controls.Add(lb);
}
}
rows++;
}
}
}