将值从datagrid传递到另一个页面 [英] Passing values from datagrid to another page

查看:77
本文介绍了将值从datagrid传递到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将值从gridView传递到另一页的文本框中,并且出现以下错误

Hi Am trying to pass values from gridView to a textbox in another page and i get the following error

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 10:     protected void Page_Load(object sender, EventArgs e)
Line 11:     {
Line 12:         this.txtPatientName.Text = Request.QueryString["name"].ToString();
Line 13:     }
Line 14: }




以下是我第一页的代码




Below is the code from my first page

foreach (GridViewRow row in grdAvailableStuff.Rows)
       {
           string name = row.Cells[1].Text;
           string time = row.Cells[2].Text;
           Response.Redirect("AddPatients.aspx?name=" + name.ToString());
       }



接下来是我的第二页



Then below is my second page

protected void Page_Load(object sender, EventArgs e)
    {
        this.txtPatientName.Text = Request.QueryString["name"].ToString();
    }

推荐答案


在下面尝试此代码
Hi,
Try this code below
if (Request.QueryString["name"]!=null && !string.IsNullOrEmpty(Request.QueryString["name"].ToString()))
{
    this.txtPatientName.Text = Request.QueryString["name"].ToString();
}



在第一页上,为什么每个gridview行都将名称值重定向到另一页?在这种情况下,它将无法工作,基于某些事件/业务逻辑会发生重定向.考虑一下,希望这将解决您的对象引用错误.



And on first page why each gridview row is redirecting name value to other page? In this case it wont work, redirection happen based on some event/business logics. Give this a thought.Hope this will solve your Object reference error.


以datakey作为名称,并在gridview中使用gridview Delete命令,并根据您的需要更改delete命令的文本名称. >
Take datakey as name and take gridview deleting command in gridview and change text name of delete command as per you.
protected void EmployeeGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    string Name= EmployeeGridView.DataKeys[e.RowIndex].Value.ToString();
    Response.Redirect("AddPatients.aspx?EmployeeId=" + Name);
}






然后在下一页的加载事件中
做某事






then on load event of next page
do something

protected void Page_Load(object sender, EventArgs e)
    {  string Name= Request.QueryString["Name"];
        this.txtPatientName.Text = Name;
    }


希望 [ ^ ]也可能会为您提供帮助.
Hope this[^] also might help you.


这篇关于将值从datagrid传递到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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