Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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

C#
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 
        }

Thanks
Posted
Updated 6-Mar-12 18:50pm
v2

1 solution

hi,

use template field in that template field use link button like following
XML
<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

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

////your code
   }


best luck
 
Share this answer
 
v2
Comments
nawabprince 7-Mar-12 2:54am    
but i want to show only client name nt clientID..clientID is bind with label its visible hide..and linkbutton i want to show clientname and after click on client name means click on button .it populate another gridview..
Nilesh Patil Kolhapur 7-Mar-12 3:40am    
k i will update it for u
Nilesh Patil Kolhapur 7-Mar-12 3:43am    
check it! it works ok
nawabprince 7-Mar-12 4:54am    
Thanks alot Nilesh..its all want i really want..thanks again..
Nilesh Patil Kolhapur 8-Mar-12 4:38am    
welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900