Gridview调用另一个gridview. [英] Gridview call another gridview..

查看:104
本文介绍了Gridview调用另一个gridview.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击第一个GridView的任何行时,我想显示另一个GridView.
我在第一个GridView的选定索引事件中无法找到特定行的索引.

在第一个GridView中,我有客户端名称,在第二个GridView中,我具有根据客户端的项目名称.
像client1有2个项目,client2有5个项目.

我想单击第一个GridView的第一行,这意味着单击client1 2项目将显示在第二个GridView中.
我正在使用ASP.NET Web应用程序.

谢谢..
这是代码:

I would like to show another GridView when I click any row of first GridView.
I have problem to find out index of particular row at selected index event of first GridView.

In the first GridView I have client names and in the second GridView I have project name according to the client.
Like client1 has 2 projects and client2 has 5 projects.

I would like when I click on first row of first GridView, meaning click on client1 2 projects show in the second GridView.
I am Working in ASP.NET Web Application.

Thanks..
Here is the code:

protected void grdClient_SelectedIndexChanged(object sender, EventArgs e)
      {
          Project ObjProject = new Project();
          int userClientID;
          userClientID = Convert.ToInt32(((Label)(grdClient.FindControl("lbUserClientID"))).Text);// Object reference not set to an instance of an object.
          ObjProject.UserClientID = userClientID;

          grdProject.DataSource = ObjProject.GetProjectList();
          grdProject.DataBind();
      }


我无法在SelectedIndex事件中键入标签值.


I am unable to typecast label value at SelectedIndex event.

推荐答案

GridViewRow row = ItemsGridView.SelectedRow


Project ObjProject = new Project();
            int userClientID;
            userClientID = Convert.ToInt32(((Label)(row.Cells[0].FindControl("lbUserClientID"))).Text);// Object reference not set to an instance of an object.
            ObjProject.UserClientID = userClientID;
 
            grdProject.DataSource = ObjProject.GetProjectList();
            grdProject.DataBind();


为什么不使用SelectedValue属性?
如果您的gridView设置了DataKeyNames属性,则无需使用那么长的方法即可检索所需的值.

Why don''t you use SelectedValue property?
If your gridView has DataKeyNames property set you don''t have to use such long way to retrieve desired value.

protected void grdClient_SelectedIndexChanged(object sender, EventArgs e)
{
    if(grdClient.SelectedValue != null)
    {
       Project ObjProject = new Project();
       int userClientID;
       userClientID = int.Parse(grdClient.SelectedValue.ToString());
       ObjProject.UserClientID = userClientID;

      grdProject.DataSource = ObjProject.GetProjectList();
      grdProject.DataBind();
    }
}


这篇关于Gridview调用另一个gridview.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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