关于数据列表和数据列表中的控制 [英] regarding datalist and cotrols in datalist

查看:71
本文介绍了关于数据列表和数据列表中的控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用带有文本框,按钮和标签控件的数据列表视图,但是每当尝试为该控件编写代码时,都没有在.cs文件中获取该控件ID,这是什么原因导致程序在运行时没有任何错误帮助我.

I am using datalist view in my application with textbox,button and lable controls but whenever am trying to write the code for that controls am not getting that controls id in .cs file what is the problem programme is running without any errors help me .

推荐答案

检查
runat="server"

是否存在.


为此,您必须首先找到像这样的控件:
for this you have to find controls first like this :
foreach( var item in DataList1.Items )
{
    Label label1 = (Label)item.FindControl( "Label1" );
    ... // same for textbox just replace lable by textbox.
}


对于按钮单击事件,请使用像这样的item_command名称:
例如,按钮CommandName ="Item".


and for button click event use item_command name like this :
For Example the button CommandName= "Item".

if (e.CommandName == "Item")
{
Label label1 = (Label)DataList1.Items[e.Item.ItemIndex].FindControl("Label1");
// do what ever you want to do...
}


希望对您有帮助.
如果有帮助,请不要忘记将其标记为答案. :)


Hope this will help you.
Don''t forget to mark as answer if it helps. :)


这篇关于关于数据列表和数据列表中的控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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