How to check that Dynamically created checkbox checked or not? - c#

I've created some dynamic checkboxes in table header row.
If the checkbox is checked , table will have another row with a textbox.
Checkbox changed event is firing very well but when I'm trying to check whether the checkbox is checked or not , it's generating exception :
Object Reference not set to an instance of an object.
Here is my code :
Creating Dynamic controls here :
TableRow thead = new TableRow();
for (int i = 0; i < dt_fundtype.Rows.Count; i++)
{
TableCell td = new TableCell();
CheckBox chk = new CheckBox();
chk.ID = "fund_" + dt_fundtype.Rows[i]["fund_type_cd"];
chk.Text = dt_fundtype.Rows[i]["fund_type"].ToString();
chk.AutoPostBack = true;
chk.CheckedChanged += new EventHandler(Chk_Fund_CheckedChange);
td.Controls.Add(chk);
thead.Cells.Add(td);
}
tbl_fundtype.Rows.Add(thead);
Checkbox checked changed event :
public void Chk_Fund_CheckedChange(object sender, EventArgs e)
{
TableRow tr = new TableRow();
for (int i=0;i<tbl_fundtype.Rows[0].Cells.Count;i++)
{
string DynamicChkID ="fund_"+ dt_fundtype.Rows[i]["fund_type_cd"].ToString();
CheckBox chk = new CheckBox();
chk = (CheckBox)tbl_fundtype.Rows[0].Cells[i].FindControl("DynamicChkID");
if (chk.Checked == true)//Here is the Exception
{
TableCell td = new TableCell();
td.Text = "Test";
tr.Cells.Add(td);
}
}
tbl_fundtype.Rows.Add(tr);
hfTab.Value = "fund";
collapsestate = "expand";
}
The event is firing very well , but when I check that the checkbox is checked or not there's an exception.
How can I resolve this problem ? Kindly Help me Please

This is the example I use which work for me.
I've simplified the binding logic and lookup logic etc, to illustrate
protected void Page_Load(object sender, EventArgs e)
{
AddStuff();
}
private void AddStuff()
{
TableRow thead = new TableRow();
for (int i = 0; i < 10; i++)
{
TableCell td = new TableCell();
CheckBox chk = new CheckBox();
chk.ID = "fund_" + i;
chk.Text = i.ToString();
chk.AutoPostBack = true;
chk.CheckedChanged += new EventHandler(Chk_Fund_CheckedChange);
td.Controls.Add(chk);
thead.Cells.Add(td);
}
tbl_fundtype.Rows.Add(thead);
}
public void Chk_Fund_CheckedChange(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
var chk = tbl_fundtype.FindControl("fund_" + i) as CheckBox;
if (chk.Checked)
{
//I am checked
}
}
}
And on my markup page I have:
<asp:Table ID="tbl_fundtype" runat="server" />

protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = Rowcreation();
TableRow thead = new TableRow();
for (int i = 0; i < dt.Rows.Count; i++)
{
TableCell td = new TableCell();
CheckBox chk = new CheckBox();
chk.ID = "fund" + dt.Rows[i]["ID"];
chk.Text = dt.Rows[i]["Name"].ToString();
chk.AutoPostBack = true;
chk.CheckedChanged += new EventHandler(chk_fun_checkedchange);
td.Controls.Add(chk);
thead.Controls.Add(td);
}
pnl.Controls.Add(thead);
}
public void chk_fun_checkedchange(object sender, EventArgs e)
{
DataTable dt = Rowcreation();
for (int i = 0; i < dt.Rows.Count; i++)
{
CheckBox chkbx = (CheckBox ) pnl.Parent.Controls[0].FindControl("fund"+dt.Rows [i]["ID"]);
if (chkbx.Checked == true)
{
lbl.Text = chkbx.Text;
}
}
}
private DataTable Rowcreation()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Name");
DataRow dr = dt.NewRow();
dr["ID"] = "1";
dr["Name"] = "Name1";
dt.NewRow();
dt.Rows.Add(dr);
DataRow dr1 = dt.NewRow();
dr1["ID"] = "2";
dr1["Name"] = "Name2";
dt.Rows.Add(dr1);
dt.NewRow();
DataRow dr2 = dt.NewRow();
dr2["ID"] = "3";
dr2["Name"] = "Name3";
dt.Rows.Add(dr2);
return dt;
}

Related

How do I get the selected Value from dynamically created CheckBox?

I added CheckBox controls dynamically from the database to FlowLayOutPanel. How do I get and store all selected values?
My sample code is here...
private void dynamicCheck()
{
//throw new NotImplementedException();
DataSet1TableAdapters.tbl_subjects1TableAdapter ta =
new DataSet1TableAdapters.tbl_subjects1TableAdapter();
DataTable dt = ta.GetData();
foreach (DataRow row in dt.Rows)
{
CheckBox chk = new CheckBox();
chk.Width = 90;
chk.Text = row[1].ToString();
chk.CheckedChanged += new
EventHandler(changeCheck);
flowLayoutPanel1.Controls.Add(chk);
}
}
private void changeCheck(object sender, EventArgs e)
{
//throw new NotImplementedException();
CheckBox chk = sender as CheckBox;
if (chk.Checked)
{
//MessageBox.Show("checked item" + chk.Text);
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
}
I'd do this:
private List<CheckBox> _checkBoxes = null;
private void DynamicCheck()
{
DataSet1TableAdapters.tbl_subjects1TableAdapter ta =
new DataSet1TableAdapters.tbl_subjects1TableAdapter();
DataTable dt = ta.GetData();
_checkBoxes = dt.Rows.Cast<DataRow>().Select(row =>
{
CheckBox chk = new CheckBox();
chk.Width = 90;
chk.Text = row[1].ToString();
chk.CheckedChanged += new EventHandler(changeCheck);
flowLayoutPanel1.Controls.Add(chk);
return chk;
}).ToList();
}
Now you can access each CheckBox in _checkBoxes.

Setting Rowspan for Dynamic Rows in asp.net Table Control

I've created an asp.net table and added rows to the table dynamically that is using Backend ( C# ) .
The First Column of the Rows should have Rowspan .
The rows are being added very fine and the Rowspan is also added fine but when the Postback occurs , The Rowspans gets changes automatically .
Can any one please help me to solve this problem :(
This is when the page loads First Time:
This is when PostBack Occured First Time :
This is when Postback Occured Second Time :
Thanks in advance
Here is my complete code :
.aspx Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
.tbl {
border:1px solid #000000;
}
.tbl td,th {
border:1px solid #000000;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Table runat="server" ID="tbl_fund" CssClass="tbl"></asp:Table>
<asp:Button runat="server" Text="Do Post Back" />
</div>
</form>
</body>
</html>
C# Code :
protected void Page_Load(object sender, EventArgs e)
{
PrintFundChanges();
}
public void PrintFundChanges()
{
//***************************Header Started*****************************
TableRow tr_head = new TableRow();
TableHeaderCell th1 = new TableHeaderCell();
th1.Text = "CNIC";
TableHeaderCell th2 = new TableHeaderCell();
th2.Text = "Field Name";
TableHeaderCell th3 = new TableHeaderCell();
th3.Text = "Updated Value";
TableHeaderCell th4 = new TableHeaderCell();
th4.Text = "Current Value";
TableHeaderCell th5 = new TableHeaderCell();
CheckBox chk_head = new CheckBox();
chk_head.ID = "chk_fund";
chk_head.CheckedChanged += new EventHandler(Chk_Fund_CheckedChanged);
chk_head.Text = "Approve / Disapprove";
chk_head.AutoPostBack = true;
th5.Controls.Add(chk_head);
TableHeaderCell th6 = new TableHeaderCell();
th6.Text = "Table Name";
th6.Style.Add("display", "none");
TableHeaderCell th7 = new TableHeaderCell();
th7.Text = "Column Name";
th7.Style.Add("display", "none");
TableHeaderCell th8 = new TableHeaderCell();
th8.Text = "pk_code";
th8.Style.Add("display", "none");
TableHeaderCell th9 = new TableHeaderCell();
th9.Text = "pk2_code";
th9.Style.Add("display", "none");
TableHeaderCell th10 = new TableHeaderCell();
th10.Text = "action_type";
th10.Style.Add("display", "none");
th1.Style.Add("width", "20%");
th2.Style.Add("width", "20%");
th3.Style.Add("width", "20%");
th4.Style.Add("width", "20%");
tr_head.Cells.Add(th1);
tr_head.Cells.Add(th2);
tr_head.Cells.Add(th3);
tr_head.Cells.Add(th4);
tr_head.Cells.Add(th5);
tr_head.Cells.Add(th6);
tr_head.Cells.Add(th7);
tr_head.Cells.Add(th8);
tr_head.Cells.Add(th9);
tr_head.Cells.Add(th10);
tbl_fund.Rows.Add(tr_head);
//****************************Header Ended*******************************
//****************************Print Updated Data Started*************************
//Getting distinct primary key data
//DataTable dt_DistinctPk = dt_FundUpdatedFields.DefaultView.ToTable(true, "pk_code");
DataTable dt_DistinctPk = new DataTable();
dt_DistinctPk.Columns.Add(new DataColumn("pk_code", typeof(string)));
DataRow dr = dt_DistinctPk.NewRow();
dr["pk_code"] = "123";
dt_DistinctPk.Rows.Add(dr);
dr = dt_DistinctPk.NewRow();
dr["pk_code"] = "456";
dt_DistinctPk.Rows.Add(dr);
for (int i = 0; i < dt_DistinctPk.Rows.Count; i++)
{
TableCell td_pk = new TableCell();
td_pk.Text = "<b style='font-size:13px !important;'>" + dt_DistinctPk.Rows[i]["pk_code"].ToString() + "</b>";
//int numberOfRecords = dt_FundUpdatedFields.Select("pk_code = " + dt_DistinctPk.Rows[i]["pk_code"].ToString()).Length;
int numberOfRecords =5;
td_pk.RowSpan = numberOfRecords;
bool IsAddAtOnce = true;
for (int j = 0; j < 5; j++)
{
string field_name_lable = "Column name here";
TableRow tr = new TableRow();
TableCell td1 = new TableCell();
td1.Text = field_name_lable;
TableCell td2 = new TableCell();
TableCell td3 = new TableCell();
td2.Text = "New Value here";
td3.Text = "Old Value here";
TableCell td4 = new TableCell();
CheckBox chk = new CheckBox();
chk.ID = "chk_" +j;
//td4.Controls.Add(chk);
TableCell td5 = new TableCell();
td5.Text = "tbl_name";
td5.Style.Add("display","none");
TableCell td6 = new TableCell();
td6.Text = "field_name";
td6.Style.Add("display", "none");
TableCell td7 = new TableCell();
td7.Text = j.ToString();
td7.Style.Add("display", "none");
TableCell td8 = new TableCell();
td8.Text = j.ToString();
td8.Style.Add("display", "none");
TableCell td9 = new TableCell();
td9.Text = "1";
td9.Style.Add("display", "none");
if (IsAddAtOnce)
{
tr.Cells.Add(td_pk);
IsAddAtOnce = false;
}
tr.Cells.Add(td1);
tr.Cells.Add(td2);
tr.Cells.Add(td3);
tr.Cells.Add(td4);
tr.Cells.Add(td5);
tr.Cells.Add(td6);
tr.Cells.Add(td7);
tr.Cells.Add(td8);
tr.Cells.Add(td9);
tbl_fund.Rows.Add(tr);
if (j ==5 - 1)//Last Termination of Loop
{
//Printing Attachments
td_pk.RowSpan = td_pk.RowSpan + 1;
td1 = new TableCell();
td1.Text = "CNIC Attachment";
td2 = new TableCell();
Image img_new = new Image();
// img_new.ImageUrl = "ImgHandler.ashx?typ=Newfund&emp=" + Requestor + "&pk=" + dt_FundUpdatedAttachments.Rows[k]["pk_code"].ToString();
td2.Controls.Add(img_new);
td3 = new TableCell();
Image img_old = new Image();
//img_old.ImageUrl = "ImgHandler.ashx?typ=Currfund&emp=" + Requestor + "&pk=" + dt_FundUpdatedAttachments.Rows[k]["pk_code"].ToString();
td3.Controls.Add(img_old);
td4 = new TableCell();
chk = new CheckBox();
//chk.ID = "chk_" + dt_FundUpdatedAttachments.Rows[k]["tbl_name"].ToString().ToUpper() + "_" + dt_FundUpdatedAttachments.Rows[k]["field_name"].ToString().ToUpper() + "_" + dt_FundUpdatedAttachments.Rows[k]["pk_code"].ToString().ToUpper() + "_";
td4.Controls.Add(chk);
td5 = new TableCell();
td5.Text = "tbl_name";
td5.Style.Add("display", "none");
td6 = new TableCell();
td6.Text ="field_name";
td6.Style.Add("display", "none");
td7 = new TableCell();
td7.Text = j.ToString();
td7.Style.Add("display", "none");
td8 = new TableCell();
td8.Text = "";
td8.Style.Add("display", "none");
td9 = new TableCell();
td9.Text = "1";
td9.Style.Add("display", "none");
tr = new TableRow();
tr.Cells.Add(td1);
tr.Cells.Add(td2);
tr.Cells.Add(td3);
tr.Cells.Add(td4);
tr.Cells.Add(td5);
tr.Cells.Add(td6);
tr.Cells.Add(td7);
tr.Cells.Add(td8);//pk2_code
tr.Cells.Add(td9);//action_type
tbl_fund.Rows.Add(tr);
}
}
}
////****************************Print New Data Ended***************************
TableRow tr_blank = new TableRow();
TableCell td_blank = new TableCell();
td_blank.Text = "Deleted Data";
td_blank.Style.Add("font-weight", "bold !important");
td_blank.Style.Add("font-size", " 16px !important");
td_blank.Style.Add("background-color", "#e3e3e3 !important");
td_blank.ColumnSpan = 10;
tr_blank.Cells.Add(td_blank);
tbl_fund.Rows.Add(tr_blank);
////****************************Print Deleted Data Started***************************
//****************************Print Deleted Data Ended***************************
}
protected void Chk_Fund_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
bool IsChecked = chk.Checked;
for (int i = 1; i < tbl_fund.Rows.Count; i++)
{
string pk_code = "";
string tbl_name = "";
string col_name = "";
string pk2_code = "";
int CellsCount = tbl_fund.Rows[i].Cells.Count;
/*In this table rowspan is used for printing cnic number,
so the row who has rowspan will have cnic column in first termination ,
while in second termination the cell count will decrease because the
row before the current row will having the rowspan.
*/
if (CellsCount == 10)
{
tbl_name = tbl_fund.Rows[i].Cells[5].Text;
col_name = tbl_fund.Rows[i].Cells[6].Text;
pk_code = tbl_fund.Rows[i].Cells[7].Text;
pk2_code = tbl_fund.Rows[i].Cells[8].Text;
}
else if (CellsCount == 9)
{
tbl_name = tbl_fund.Rows[i].Cells[4].Text;
col_name = tbl_fund.Rows[i].Cells[5].Text;
pk_code = tbl_fund.Rows[i].Cells[6].Text;
pk2_code = tbl_fund.Rows[i].Cells[7].Text;
}
if (tbl_name != "")//if it is not a blank/header row
{
CheckBox ck = new CheckBox();
string chk_id = "chk_" + tbl_name + "_" + col_name + "_" + pk_code + "_" + pk2_code;
ck = (CheckBox)tbl_fund.Rows[i].Cells[4].FindControl(chk_id);//chk_tblname_colname_pk
ck.Checked = IsChecked;
}
}
}
just change the this line from
td_pk.RowSpan = td_pk.RowSpan + 1;
to
td_pk.RowSpan = numberOfRecords + 1;

how to create oncheckedchange for dynamic checkbox

try
{
string constr1 = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
SqlConnection conn1 = new SqlConnection(constr1);
conn1.Open();
//passing a query to fetch the table from database,which is entered in TextBox
DataSet ds = new DataSet();
string s2 = "select neid,keyholder from tbl_controller_settings where axxesstype='2'";
SqlDataAdapter da = new SqlDataAdapter(s2, conn1);
da.Fill(ds);
DataTable dt = new DataTable();
dt = ds.Tables[0];
//creating a table dynamically
HtmlTable table = new HtmlTable();
HtmlTableRow tr = null;
HtmlTableCell tc = null;
//displaying labels for displaying column names in the table
tr = new HtmlTableRow();
for (int i = 0; i <=64; i++)
{
tc = new HtmlTableCell();
Label lbl = new Label();
if(i!=0)
lbl.Text = "Key"+" "+i.ToString();
lbl.ID = "lbl" +" "+i.ToString();
lbl.Style.Add("writing-mode", "rt-tb");
lbl.Style.Add("filter", "flipv");
tc.Height = "50px";
tc.Width = "150px";
tc.Controls.Add(lbl);
tr.Controls.Add(tc);
table.Controls.Add(tr);
}
//creating textboxes for displaying records information
for (int j = 0; j < dt.Rows.Count; j++)
{
tr = new HtmlTableRow();
tc = new HtmlTableCell();
Label ksid = new Label();
ksid.ID = "ksid"+j;
ksid.Text = dt.Rows[j][0].ToString();
tc.Controls.Add(ksid);
tr.Controls.Add(tc);
for (int k = 1; k <= 64;k++ )
{
tc = new HtmlTableCell();
CheckBox chk = new CheckBox();
chk.ID = "txt" + j + k;
chk.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
if (k <= Convert.ToInt32(dt.Rows[j][1]))
chk.Enabled = true;
else
chk.Enabled = false;
tc.Controls.Add(chk);
tr.Controls.Add(tc);
}
table.Controls.Add(tr);
}
pnlkeys.Controls.Add(table);
pnlkeys.Visible = true;
//}
}
catch (Exception ex)
{
throw;
}
Hello
In the Above code i have created the check box and a label button dynamically,in this 64 iteration i will be having the 64 check box.i want to get the value has when a check box is checked it should be 1 and when it is not checked it should be 0 to store in 64 columns ..please help me
try add the method in the same class file :
public static void CheckBox_CheckedChanged(object sender, EventArgs e) {
}
If you want help on how to generate the "1" when checked, please specify first where that value is to be stored.
You do not need OnCheckedChanged if you want to store their values altogether.
You can access your CheckBox's value in PostBack on Request.Form with their ID
if(Request.Form["txt11"]==null)
{
//checkbox is not checked
}
if(Request.Form["txt11"]=="on")
{
//checkbox is checked
}
You need to write this code in a loop to get all your CheckBoxes

Dropdownlist Dynamically Created into Repeater Dynamically Created asp.net

I am creating a dynamically repeater during the creation of this repeater I create some dropdownlists with autopostback = true, and add the handler selectindexchanged. I wonder how to keep bind the repeater inside (! IsNotPostBack) without losing the repeater information. In summary if I keep bind the repeater in notpostback, when I change the dropdownlist the repeater is not rendered.
Well confused? I will post part of the code:
Default.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRepeater2();
}
}
private void BindRepeater2()
{
Repeater rContainer = null;
HtmlGenericControl div = new HtmlGenericControl("div");
HtmlGenericControl table = new HtmlGenericControl("table");
div.Attributes.Add("class", "CompApp_TableScroll");
table.Attributes.Add("class", "CompApp_DataTable");
table.Attributes.Add("width", "100%");
try
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Address", typeof(string));
dt.Columns.Add("DropDown", typeof(string));
dt.Rows.Add(25, "Rk", "Gurgaon");
dt.Rows.Add(50, "Sachin", "Noida");
dt.Rows.Add(10, "Nitin", "Noida");
dt.Rows.Add(21, "Aditya", "Meerut");
DataSet ds = new DataSet();
ds.Tables.Add(dt);
if (dt.Rows.Count > 0)
{
rContainer = new Repeater();
rContainer.DataSource = dt;
rContainer.DataBind();
foreach (DataTable dtCluster in ds.Tables)
{
rContainer = new Repeater();
rContainer.ItemTemplate = new RepeaterTemplate2(ListItemType.Item);
rContainer.HeaderTemplate = new RepeaterTemplate2(ListItemType.Header);
rContainer.FooterTemplate = new RepeaterTemplate2(ListItemType.Footer);
rContainer.DataSource = dtCluster;
table.Controls.Add(rContainer);
}
div.Controls.Add(table);
}
div1.Controls.Add(div);
rContainer.ItemDataBound += rContainer_ItemDataBound;
rContainer.ID = "rpt1";
rContainer.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}
void rContainer_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList ddl = new DropDownList();
ddl = (DropDownList)e.Item.FindControl("ddl");
ddl.AutoPostBack = true;
ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
}
}
private void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl2 = new DropDownList();
ddl2 = (DropDownList)sender;
Response.Write(ddl2.SelectedValue);
}
RepeaterTemplate2.cs
public class RepeaterTemplate2 : System.Web.UI.ITemplate
{
ListItemType vTemplateItemType = ListItemType.Separator;
public RepeaterTemplate2(ListItemType pListItemType)
{
vTemplateItemType = pListItemType;
}
public void InstantiateIn(System.Web.UI.Control container)
{
Literal lc = new Literal();
HtmlGenericControl tr = new HtmlGenericControl("tr");
HtmlGenericControl td = new HtmlGenericControl("td");
switch (vTemplateItemType)
{
case ListItemType.Header:
td.InnerHtml = "<u>EmpID</u>";
tr.Controls.Add(td);
td = new HtmlGenericControl("td");
td.InnerHtml = "<u>Name</u>";
tr.Controls.Add(td);
td = new HtmlGenericControl("td");
td.InnerHtml = "<u>Address</u>";
tr.Controls.Add(td);
td = new HtmlGenericControl("td");
td.InnerHtml = "<u>DropdDown</u>";
tr.Controls.Add(td);
break;
case ListItemType.Footer:
break;
case ListItemType.Item:
; break;
}
tr.DataBinding += new EventHandler(lc_DataBinding);
container.Controls.Add(tr);
}
private void lc_DataBinding(object sender, EventArgs e)
{
HtmlGenericControl tr = (HtmlGenericControl)sender;
RepeaterItem vContainer = (RepeaterItem)tr.NamingContainer;
DataRowView row = (DataRowView)vContainer.DataItem;
if (row != null)
{
for (int i = 0; i < row.DataView.Table.Columns.Count; i++)
{
HtmlGenericControl td = new HtmlGenericControl("td");
if (i == 3)
{
DropDownList ddl = new DropDownList();
ddl.ID = "ddl";
ddl.Items.Add(new ListItem("valor 1", "1"));
ddl.Items.Add(new ListItem("valor 2", "2"));
td.Controls.Add(ddl);
}
else
{
td.InnerHtml = row[i].ToString();
}
tr.Controls.Add(td);
}
}
}
}

C#.net how to add an image into a table cell dynamically by code

I am trying to add an image into a table that I'm making dynamically by code behind.
However the image is not added to the cell.
All the other codes I'm finding are talking about an htmltable which is not the same as table();
public partial class Children_nihul_1 : System.Web.UI.Page
{
protected string mychildrenlist;
protected void Page_Init(object sender, EventArgs e)
{
var cases = new List<string>();
System.Web.UI.WebControls.Image myGamepic1 = new System.Web.UI.WebControls.Image();
// var myGamepic1 = new Image();
myGamepic1.ImageUrl = "~/img/inner-page/Game1.png";
myGamepic1.Height = 30;
//this part is only a call for data from database- not relavent to the
qustion./
DataSet ds = new DataSet();
string x = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("./App_Data/DatabaseGames.accdb") + ";";
string y = "select * from Students";
mySql myq = new mySql();
ds = myq.sqlRet(x, y);
rowlist = ds.Tables[0].Rows.Count;
for (int i = 0; i < rowlist; ++i)
{
cases.Add(ds.Tables[0].Rows[i][1].ToString());
}
//my table creation
Table table = new Table();
table.BorderStyle = BorderStyle.None;
//Add Header Row
TableRow row = new TableRow();
TableHeaderCell headerCell = new TableHeaderCell();
headerCell.Text = "aaa";
row.Controls.Add(headerCell);
headerCell = new TableHeaderCell();
headerCell.Text = "ccc";
row.Controls.Add(headerCell);
table.Controls.Add(row);
for (int i = 0; i < rowlist; ++i)
{
//Add DataRow
row = new TableRow();
TableCell cell = new TableCell();
cell.Text = cases[i];
row.Controls.Add(cell);
cell = new TableCell();
cell.Controls.Add(myGamepic1);
row.Controls.Add(cell);
table.Controls.Add(row);
}
Panel1.Controls.Add(table);
Panel1.Controls.Add(myGamepic1);
}
}
Try something like this. Works for me when adding an image dynamic using code behind.
cell11.Text = string.Format("<img src='images/close_icon.png' />");

Categories