int userid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
TextBox textname= ((System.Web.UI.WebControls.TextBox(GridView1.Rows[e.RowIndex].Cells[1].Controls[1])).Text;
TextBox textdob = (((System.Web.UI.WebControls.TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[1]))).Text;
TextBox textrole = ((System.Web.UI.WebControls.ListControl)(((System.Web.UI.WebControls.DropDownList)(((System.Web.UI.Control)(GridView1.Rows[e.RowIndex].Cells[3].Controls[1])))))).SelectedIndex.ToString();
获取该错误TextBox textname 文本框textdob 文本框文本
答案 0 :(得分:0)
试
textname.Text = ((System.Web.UI.WebControls.ListControl)(((System.Web.UI.WebControls.DropDownList)(((System.Web.UI.Control)(GridView1.Rows[e.RowIndex].Cells[3].Controls[1])))))).SelectedIndex.ToString();
你不能在文本框本身添加一个字符串
答案 1 :(得分:0)
查看以下代码行
TextBox textname = ((System.Web.UI.WebControls.TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[1])).Text;
((System.Web.UI.WebControls.TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[1])).Text
是一个字符串,但您要将其分配给textname
TextBox
,这就是您收到错误的原因。
将上述代码更改为
TextBox textname = (System.Web.UI.WebControls.TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[1]);
然后你可以这样得到文本
string name = txtname.Text;
同样的事情适用于第二个文本框
TextBox textdob = (System.Web.UI.WebControls.TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[1]);
// get the dob
string dbo = textdob.Text;
对于下拉列表,您必须将其分配给DropDownList
而不是TextBox
DropDownList ddlRole = (System.Web.UI.WebControls.DropDownList)(GridView1.Rows[e.RowIndex].Cells[3].Controls[1]);
// get the selected index
int selectedRoleIndex = ddlRole.SelectedIndex;