Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In that Grid view I have one column that column contain Name of the person.when I click that name then show the details of person in another grid view
Posted
Comments
sanjayabishi 27-Sep-12 6:14am    
Hi Boopathi you can put the link button in the item template and bind the name as field in the grid view column. If you want to see the person details, Bind the person id or which is primary key value in the hidden field. Get the hidden field in the link button click event in code behind. and fetch the details of the person as per the key value and show the details in separage grid.

You can add template field as follows:

ASP.NET
<asp:TemplateField>
   <itemtemplate>
                         <asp:linkbutton runat="server" id="lnkName" text="<%# DataBinder.Eval (Container.DataItem, "PersonNameColumnName") %>" commandname="PersonDetail" commandarguement="DataBinder.Eval (Container.DataItem, "IDColumnName") %>" />
    </itemtemplate>
  </asp:templatefield>



Then you can handle the row command event of grid. Inside which you can check if command name is "PersonDetail"? If yes then you can bind another grid with details of the person whose id can be retrieved from Command Arguement.
 
Share this answer
 
v2
ASP.NET
<asp:templatefield headertext="User" xmlns:asp="#unknown">
    <itemtemplate>

        <asp:linkbutton runat="server" id="btnGetDetails" commandargument="<%#Eval("ID") %>" commandname="GetDtls" text="<%#Eval("Name") %>" />
    </itemtemplate>
</asp:templatefield>


C#
protected void gvContacts_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if(e.CommmondName=="GetDtls")
    {
        int intContactID =Convert.ToInt32( e.CommandArgument);  //find the user id you want to get details..
        //Do your Get Details logic here based on "intContactID".. 
    }
}
 
Share this answer
 

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