填充标准的dyanamically [英] Populating the lable dyanamically

查看:73
本文介绍了填充标准的dyanamically的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI专家





我有一个包含3行和3列的数据表。我想要将它绑定到webform中。 Lable可以动态填充。请指导我。



以下是我以前的代码。但它对我不起作用。



TableRow tr = new TableRow();

tr.ID =tr+ count;

tc.ID =tc+ tablecellid;

lbl.ID =ID+ tablecellid;

lbl.Text = dtfinal。行[i] [TEXT]。ToString();

tablecellid = tablecellid + 1;

tc.ID =tc+ tablecellid;

lbl.ID =ID+ tablecellid;

lbl.Text = dtfinal.Rows [i] [DESC]。ToString();

count = count + 1;

tablecellid = tablecellid + 1;

tc.Controls.Add(lbl);

tr.Cells.Add (tc);

Table1.Rows.Add(tr);





Rgds

Jagadesh

解决方案

 DataTable dt  //  您的DataTable ..  

foreach (DataRow dr in dt.Rows)
{
TableRow tr = new TableRow();
tr.ID = tr + count;
tc.ID = tc + tablecellid;
lbl.ID = ID + tablecellid;
lbl.Text = dr [ TEXT]。ToString();
tablecellid = tablecellid + 1 ;
tc.ID = tc + tablecellid;
lbl.ID = ID + tablecellid;
lbl.Text = dr [ DESC]。ToString();
count = count + 1 ;
tablecellid = tablecellid + 1 ;
tc.Controls.Add(lbl);
tr.Cells.Add(tc);
Table1.Rows.Add(tr);
}


HI ALL



我为每一行添加了我的控件。



请找到以下代码。这解决了我的问题



TableRow tr = new TableRow();

TableCell tc = new TableCell();

Label lbl = new Label();

tr.ID =tr+ count;

tc.ID =tc+ tablecellid;

lbl.ID =ID+ tablecellid;

lbl.Text = dr [TEXT]。ToString();

tablecellid = tablecellid + 1 ;

标签lbl2 =新标签();

tc.ID =tc+ tablecellid;

lbl2.ID =ID + tablecellid;

lbl2.Text = dr [DESC]。ToString();

标签lbl3 =新标签();

tc.ID =tc+ tablecellid;

lbl3.ID =ID+ tablecellid;

lbl3.Text = dr [STATUS]。ToString() ;

count = count + 1;

表cellid = tablecellid + 1;

tc.Controls.Add(lbl);

tc.Controls.Add(lbl2);

tc。 Controls.Add(lbl3);

tr.Cells.Add(tc);

Table1.Rows.Add(tr);


HI EXPERTS


I had a datatable which contains 3rows and 3 columns. I want this to be bind in a lable into the webform. Lable to be populate Dynamically. Kindly guide me.

Below is the code i used to do. But it is not working for me.

TableRow tr = new TableRow();
tr.ID = "tr" + count;
tc.ID = "tc" + tablecellid;
lbl.ID = "ID" + tablecellid;
lbl.Text = dtfinal.Rows[i]["TEXT"].ToString();
tablecellid = tablecellid + 1;
tc.ID = "tc" + tablecellid;
lbl.ID = "ID" + tablecellid;
lbl.Text = dtfinal.Rows[i]["DESC"].ToString();
count = count + 1;
tablecellid = tablecellid + 1;
tc.Controls.Add(lbl);
tr.Cells.Add(tc);
Table1.Rows.Add(tr);


Rgds
Jagadesh

解决方案

DataTable dt // Your DataTable..

foreach(DataRow dr in dt.Rows)
{
TableRow tr = new TableRow();
tr.ID = "tr" + count;
tc.ID = "tc" + tablecellid;
lbl.ID = "ID" + tablecellid;
lbl.Text = dr["TEXT"].ToString();
tablecellid = tablecellid + 1;
tc.ID = "tc" + tablecellid;
lbl.ID = "ID" + tablecellid;
lbl.Text = dr["DESC"].ToString();
count = count + 1;
tablecellid = tablecellid + 1;
tc.Controls.Add(lbl);
tr.Cells.Add(tc);
Table1.Rows.Add(tr);
}


HI ALL

I added my control for each row.

Pls find the below code. This solved my problem

TableRow tr = new TableRow();
TableCell tc = new TableCell();
Label lbl = new Label();
tr.ID = "tr" + count;
tc.ID = "tc" + tablecellid;
lbl.ID = "ID" + tablecellid;
lbl.Text = dr["TEXT"].ToString();
tablecellid = tablecellid + 1;
Label lbl2 = new Label();
tc.ID = "tc" + tablecellid;
lbl2.ID = "ID" + tablecellid;
lbl2.Text = dr["DESC"].ToString();
Label lbl3 = new Label();
tc.ID = "tc" + tablecellid;
lbl3.ID = "ID" + tablecellid;
lbl3.Text = dr["STATUS"].ToString();
count = count + 1;
tablecellid = tablecellid + 1;
tc.Controls.Add(lbl);
tc.Controls.Add(lbl2);
tc.Controls.Add(lbl3);
tr.Cells.Add(tc);
Table1.Rows.Add(tr);


这篇关于填充标准的dyanamically的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆