将异常视为无法将类型为'asp.home_aspx'的对象强制转换为'system.web.ui.webcontrols.linkbutton'。 [英] Getting exception as unable to cast object of type 'asp.home_aspx' to type 'system.web.ui.webcontrols.linkbutton'.

查看:63
本文介绍了将异常视为无法将类型为'asp.home_aspx'的对象强制转换为'system.web.ui.webcontrols.linkbutton'。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void grd1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
 string Eve1 = ViewState["SecondStatus"].ToString();
if (Eve1 == "Completeddays")
{
  lnkCompleted1_Click(this, new EventArgs());
}
}










protected void lnkCompleted1_Click(object sender, EventArgs e)
{
        strStatus = "Completedays";
        grd1.Visible = true;
        User1 = ((LinkButton)sender).CommandArgument; // here i am getting error as Unable to cast object of type 'ASP.home_aspx' to type 'System.Web.UI.WebControls.LinkButton'.
        DataTable dt = adm.getProjectsbyStatusbyUser(strStatus, txtDate2.Text, User1);
}










To be more clear i have two grids one grid just displays the count of tasks and username for example and on clicking that number 
i will get second grid with paging as it has so many records and on clicking paging i need to go to the event lnkCompleted1_Click
by passing username of that particular user whom we are viewing in second grid suppose if we click radha when i click on paging of
second grid i should pass that user radha to lnkCompleted1_Click event

<pre lang="text">User                   Completed batches
nandini                                         23
geetha                                           2
radha                                            4





我尝试了什么:



i因为



What I have tried:

i am getting exception as

Unable to cast object of type 'ASP.home_aspx' to type 'System.Web.UI.WebControls.LinkButton'. in tis event lnkCompleted1_Click

推荐答案

试试这个



try this

protected void lnkCompleted1_Click(object sender, EventArgs e)
       {
           string  User1 = ((LinkButton)sender).CommandArgument;
           ViewState["User1"] = User1;
           MyFunction();
       }

       protected void MyFunction() {
           strStatus = "Completedays";
           grd1.Visible = true;
           string User1 = ViewState["User1"]+"";
           DataTable dt = adm.getProjectsbyStatusbyUser(strStatus, txtDate2.Text, User1);

       }

       protected void grd1_PageIndexChanging(object sender, GridViewPageEventArgs e)
       {
           string Eve1 = ViewState["SecondStatus"].ToString();
           if (Eve1 == "Completeddays")
           {
               MyFunction();
           }
       }


这篇关于将异常视为无法将类型为'asp.home_aspx'的对象强制转换为'system.web.ui.webcontrols.linkbutton'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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