
你试试这样写
string name = (TextBox)(DataList1Items[0]FindControl["IdLabel"])Text;
注意:你findcontrol方法里的“IdLabel”从命名来看貌似是一个Label控件,肯定不能强制转换成TextBox控件你查查在DATALIST里面的TextBox的ID名然后填进去你试试
<asp:label id="mess" runat="server" />
<%
int i=intparse(messText);
//转换数据类型就可以了,C#是强类型语言,一板一眼的
%>
貌似之前的回答没有解决你的问题,刚才做了测试,确实无法通过静态变量来处理。
你可以通过一个HiddenField控件来储存到底点了几次Button, 代码如下:
ASPX:
<form id="form1" runat="server"><div>
<asp:Label runat="server" id="label1">This is a test</asp:Label>
<asp:Button runat="server" ID="btnGetItem" Text="Get Item" OnClick="btnGetItem_Click" />
<asp:HiddenField ID="HiddenField1" runat="server" />
</div>
</form>
ASPXcs:
protected void Page_Load(object sender, EventArgs e){
if (!PageIsPostBack)
{
HiddenField1Value = "0";
}
}
private ArrayList CreateArrayList()
{
ArrayList testList = new ArrayList();
testListAdd(4);
testListAdd(8);
testListAdd(10);
testListAdd(14);
testListAdd(1);
return testList;
}
protected void btnGetItem_Click(object sender, EventArgs e)
{
ArrayList testList = CreateArrayList();
int clickCount = 0;
Int32TryParse(HiddenField1ValueToString(), out clickCount);
if (testList != null && clickCount < testListCount)
{
label1Text = testList[clickCount]ToString();
}
clickCount++;
HiddenField1Value = clickCountToString();
}
希望能解答你的问题。
母板页:取值((Label)MasterFindControl("labelmaster"))Text;
赋值 ((Label)MasterFindControl("labelmaster"))Text="456";
用户控件:赋值((Label)uctopFindControl("labeltop"))Text = "123";
取值((Label)uctopFindControl("labeltop"))Text;
母版页的用户控件: 赋值((Label)((UserControl)MasterFindControl("uctop"))FindControl("labelmu"))Text = "uuuuu";
取值((Label)((UserControl)MasterFindControl("uctop"))FindControl("labelmu"))Text
以上就是关于ASP.net中DataList中获取值全部的内容,包括:ASP.net中DataList中获取值、ASP.NET怎样能将Label的值直接附给一个INT的变量、asp.net 取arraylist里面的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)