且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取在数据列表中使用的控件的值

更新时间:2023-11-25 07:58:52

如果您正在使用数据列表中的事件,则

If you are using in the datalist events then

Label Label1 = e.Item.FindControl("Label1") as Label;
string lblValue=Label1.Text;



除了数据列表事件



Other than datalist events

foreach (DataListItem dli in DataList1.Items)
            {
               Label Label1 = e.Item.FindControl("Label1") as Label;
               string lblValue=Label1.Text;
}


使用FindControl方法吗?

试试:
Using FindControl method?

Try:
//VB.NET
Dim lblId As Label = CType(Item.FindControl("lblId"),Label)


// C#
Label lblId = new Label();
lblId = (Item.FindControl("lblId")) as Label;


当我使用此标签时,出现应用程序文件中的错误,如预期的标识符
when i used this i get the error in application file like identifier expected