请帮我找出我的错误 [英] Plz...help me to find out my error

查看:84
本文介绍了请帮我找出我的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

但错误显示为tat ...

but the error displays like tat...

Unable to cast object of type 'System.Web.UI.WebControls.DataControlLinkButton' to type 'System.Web.UI.WebControls.TextBox'


组织代码


tis s t code

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"

                        CellPadding="3" CellSpacing="2" OnPageIndexChanging="GridView1_PageIndexChanging"

                        OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing"

                        OnRowUpdating="GridView1_RowUpdating" PageSize="3">
                        <Columns>
                            <asp:CommandField ShowEditButton="True" />
                            <asp:BoundField DataField="name" HeaderText="Name" />
                        </Columns>
                    </asp:GridView>





SqlConnection con1 = new SqlConnection(ConfigurationManager.AppSettings["rajarani connection"]);
           con1.Open();
           SqlDataAdapter adp1 = new SqlDataAdapter("update registerform set fullname='" + ((TextBox)GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text + "' where registerform.id='"+GridView2.Rows[e.RowIndex].Cells[0].Text+"' ", con1);
           DataSet ds1 = new DataSet();
           adp1.Fill(ds1);
           con1.Close();
           GridView2.EditIndex = -1;
           bind();




plz..help me ..




plz..help me ..

推荐答案

可以尝试,
Can you try,
((LinkButton)GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text


我希望这能解决问题.


I hope this will work.


这看起来像是您的投射不正确
It simply looks like your casting is incorrect
(TextBox)GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text



尝试在投放之前先测试对象:



Try to test the object first before casting:

if(typeof(TextBox).IsAssignableFrom(GridView2.Rows[e.RowIndex].Cells[1].Controls[0].GetType()))
{
  // ...cast value ((TextBox)GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
}
;



祝你好运!



Good luck!


我相信以下行会产生错误

((TextBox)GridView2.Rows [e.RowIndex] .Cells [1] .Controls [0]).Text

似乎在Cells [1]中,您使用的是LinkBut​​ton而不是TextBox,因此,当您将LinkBut​​ton强制类型转换为TextBox时,运行时将引发错误.

如果不清楚,请提供.aspx文件中GridView控件的标记.
I belive the following line is creating the error

((TextBox)GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text

It seems that in Cells[1] you have used a LinkButton rather than a TextBox, So when you are type casting that LinkButton to TextBox the runtime is throwing the error.

If not clear, please provide the markup of the GridView control from .aspx file.


这篇关于请帮我找出我的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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