请问如何取得DataList中的TextBox!当我点击"修改"按钮的时候想得到当前行TextBox的值!我用这种方法不行,请高手帮我!!
public void DataList_ItemCommand(object sender,DataListCommandEventArgs e)
{
if (e.CommandName=="Modify")
{
DataList1.EditItemIndex=-1; ListBind();
string a=((TextBox)e.Item.FindControl("ModifyButton")).Text;//这行报错!!
Response.Write(a);
}
}报错如下:Server Error in '/NetSystem' Application.
--------------------------------------------------------------------------------Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid.Source Error:
Line 90: ListBind();
Line 91:
Line 92: string a=((TextBox)e.Item.FindControl("ModifyButton")).Text;
Line 93:
Line 94: Response.Write(a);
Source File: d:\netsystem\productcharacteristicadd.aspx.cs Line: 92
public void DataList_ItemCommand(object sender,DataListCommandEventArgs e)
{
if (e.CommandName=="Modify")
{
DataList1.EditItemIndex=-1; ListBind();
string a=((TextBox)e.Item.FindControl("ModifyButton")).Text;//这行报错!!
Response.Write(a);
}
}报错如下:Server Error in '/NetSystem' Application.
--------------------------------------------------------------------------------Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid.Source Error:
Line 90: ListBind();
Line 91:
Line 92: string a=((TextBox)e.Item.FindControl("ModifyButton")).Text;
Line 93:
Line 94: Response.Write(a);
Source File: d:\netsystem\productcharacteristicadd.aspx.cs Line: 92
解决方案 »
- 我的Web程序在自己电脑上可以运行,可是到了别人的电脑上就报错,为什么?
- 紧急求救:datalist里的控件事件
- [求助]在ASP.net(VB)里,如何为DropDownList添加Value
- 小问题
- 如何在datagrid编辑的时候对控件进行验证
- 新生的菜鸟,请哥哥姐姐们多多关照与帮助,谢谢谢谢!!!!!(在线求助)
- 连接数据库
- 我在treeview中选择一个节点弹出另一个页面,在另一个页面中我想修改treeview中选择节点的ID应如何做?
- 字符串数组问题
- Session传递参数的标识,分传到不同页面出现问题
- 急急急!!分页、缓存
- 请问 编译后的asp.net 和 HTML 比较谁的显示速度更快?
--------------------------------------------------------------------------------Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid.Source Error:
Line 86: //{
Line 87:
Line 88: string a=((TextBox)e.Item.FindControl("ModifyButton")).Text.ToString();
Line 89:
Line 90:
if (!this.IsPostBack) DataList1.DataBind();
或 ListBind();
把这两句写在后面
我用的是:OnItemCommand="DataList_ItemCommand"是不是这里不对呢???
if (!this.IsPostBack)了吗?
你这句findcontrol写的名字是button的名字,而要得到的事textbox,
((TextBox)e.Item.FindControl("TextBoxID")).Text.ToString().Trim();
………………
DataList1.EditItemIndex=-1;
ListBind();
取TextBox的值:
((TextBox)e.Item.FindControl("TextBoxID")).Text.ToString().Trim();
取Button的值:((Button)e.Item.FindControl("ButtonID")).Text.ToString().Trim();转换要一致!
如果你要找button那么((ImageButton)e.Item.FindControl("ModifyButton"))
string a=((TextBox)e.Item.FindControl("ModifyButton")).Text;
你已经用DataList1.EditItemIndex=-1把当前行取消了,应该在操作完后再指定.