从一个gridview绑定Gridview [英] Bind Gridview from one gridview

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

问题描述

我有一个gridview,其中有两列clientID和Client Name,并且edit button delete toonon都是模板字段.

我的任务是,当我单击clientname时,它将一个新的girdview与数据projectID和项目名称列绑定.
我已经完成了行数据绑定并选择了索引事件..bt这些事件在我也单击编辑"或删除"按钮时发生..cozrowdatabound事件在整个行中发生..我只想单击客户端名称列..

我的代码在下面

I have a gridview which have two column clientID and Client Name and edit button delete buttoon all are templates fields.

my task is when i click clientname it bind one new girdview with data projectID and and project name column..

I have done with row databound and selected index event..bt these event occurs when i click on edit or delete button too..coz rowdatabound event occur for whole row..i want only click on client name columns..

My code is below

protected void grdClient_RowDataBound1(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes["OnClick"] = ClientScript.GetPostBackClientHyperlink(this.grdClient, "Select$" + e.Row.RowIndex);
            }
        }
//these code help me to select particular row...
2.



 private void grdProjectBind()//this is method to bind data with another gridview
        {
            Project ObjProject = new Project();
            try
            {

                int userClientID =Convert.ToInt32(((Label)(grdClient.Rows[grdClient.SelectedIndex].FindControl("lbUserClientID"))).Text);
               
                 //btnUserClientID

                ObjProject.UserClientID = userClientID;
                DataSet ds = new DataSet();
                ds = ObjProject.GetProjectList();
                if (ds.Tables[0].Rows.Count != 0)
                {
                    grdProject.DataSource = ds;
                    grdProject.DataBind();
                    btnAddProject.Visible = false;
                }
                else
                {
                    grdProject.DataBind();
                    btnAddProject.Visible = true;

                }
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                ObjProject = null;
            }
        
        
 protected void grdClient_SelectedIndexChanged(object sender, EventArgs e)
        {
            grdProjectBind(); //here i called the method 
        }


谢谢

推荐答案

" + e.Row.RowIndex); } } // 这些代码可帮助我选择特定的行... 2 . 私有 无效 grdProjectBind()// 这是将数据与另一个gridview绑定的方法 { Project ObjProject = Project(); 尝试 { int userClientID = Convert.ToInt32((((Label)(grdClient.Rows [grdClient.SelectedIndex] .FindControl(" lbUserClientID"))))).文本); // btnUserClientID ObjProject.UserClientID = userClientID; DataSet ds = DataSet(); ds = ObjProject.GetProjectList(); 如果(ds.Tables [ 0 ].Rows.Count!= false ; } 其他 { grdProject.DataBind(); btnAddProject.Visible = true ; } } 捕获(异常) { 投掷; } 最终 { ObjProject = ; } 受保护的 无效 grdClient_SelectedIndexChanged(对象发​​件人,EventArgs e) { grdProjectBind(); // 在这里,我将其称为方法 }
" + e.Row.RowIndex); } } //these code help me to select particular row... 2. private void grdProjectBind()//this is method to bind data with another gridview { Project ObjProject = new Project(); try { int userClientID =Convert.ToInt32(((Label)(grdClient.Rows[grdClient.SelectedIndex].FindControl("lbUserClientID"))).Text); //btnUserClientID ObjProject.UserClientID = userClientID; DataSet ds = new DataSet(); ds = ObjProject.GetProjectList(); if (ds.Tables[0].Rows.Count != 0) { grdProject.DataSource = ds; grdProject.DataBind(); btnAddProject.Visible = false; } else { grdProject.DataBind(); btnAddProject.Visible = true; } } catch (Exception) { throw; } finally { ObjProject = null; } protected void grdClient_SelectedIndexChanged(object sender, EventArgs e) { grdProjectBind(); //here i called the method }


谢谢




使用该模板字段中的模板字段使用链接按钮,如下所示


use template field in that template field use link button like following
<asp:TemplateField>
                                                                            <ItemTemplate>
                                                                                <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%#Eval("clientID")%>' Text='<%# Eval("clientname") %>' OnClick="LinkButton1_Click"></asp:LinkButton>
                                                                            </ItemTemplate>
                                                                        </asp:TemplateField>




并在后面的代码中编写以下事件




and in code behind write following event

protected void LinkButton1_Click(object sender, EventArgs e)
   {
LinkButton lnkBtn = (LinkButton)sender;
  string clientID=lnkBtn.CommandArgument;

////your code
   }



祝你好运



best luck


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

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