Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I designed a user interface to show details in a grid view(in brief). if user want to see full details of that specified row he has to click a button. then it will appear in the same page. What should I code inside the button click event?
Posted
Comments
Sergey Alexandrovich Kryukov 20-Sep-12 22:04pm    
Not "inside the button click event" (what would it mean?!), in event handler. You need to get data from the selected cell and present it the way you want somewhere else, to represent detail. That's it.
--SA

Its Simple , You need to call the Gridveiw Row Command Event Handler

See first convert the button as Template Column , as shown below and give it a command Name as shown below

XML
<asp:TemplateField HeaderText="Actions" meta:resourcekey="TemplateFieldResource9">                                <ItemTemplate>
<asp:ImageButton ID="imgView" ImageUrl="~/Images/View.gif" runat="server" CommandName="ViewIssueDetails" CommandArgument='<%# Eval("ISSUEID") %>' ToolTip="View Issue Details"  />
</ItemTemplate>                                                                                 </asp:TemplateField>



Now call the below method

C#
protected void gvTask_OnRowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ViewIssueDetails")
{
 GridViewRow row;
  row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
 }
}



GridviewRow Row , you can read the value of each columns of Grdiveiw and can display it as per your requirement

Make sure your Gridview has tagged to following command

<asp:GridView ID="gvMyTask" runat="server" Width="100%"OnRowCommand="gvTask_OnRowCommand" OnPageIndexChanging="gvTask_PageIndexChanging" AllowPaging="True" AutoGenerateColumns="False">
 
Share this answer
 
v2
Comments
gayani dassa 20-Sep-12 23:52pm    
Its not working. please help me.
Rickin Kane 21-Sep-12 0:46am    
what is not working can u show the code how you implemented it
[no name] 21-Sep-12 0:44am    
better use details view......
Here is a small example you can learn from this example:
I. Code for GridView control:
XML
 <asp:GridView id="gridview" runat="server" AutoGenerateColumns="False" OnRowCommand="gridview_OnRowCommand">
<Columns>
 <asp:Templatefield HeaderText="Id">
   <Itemtemplate>
       <asp:Label ID="lblId" runat="server" Text='<%# Eval("Id")%>' />
   </Itemtemplate>
 </asp:TemplateField>
 <asp:TemplateField>
   <Itemtemplate>
       <asp:LinkButton ID="lnkDetail" runat="server" Text="Detail"
       CommandName="Detail" CommandArgument='<%# Eval("Id")%>' />
 </Itemtemplate>
 </asp:TemplateField>
</Columns>
</asp:GridView>

II. Now write code for gridview_OnRowCommand
C#
protected void gridview_OnRowCommand(object sender, GridViewCommandEventArgs e)
 {
   if(e.CommandName == "Detail")
   { 
      //retrieve the Id from CommandArgument
      int id = Convert.ToInt32(e.CommandArgument);
      //now write your code for retrieving the detail value from database.
     //then store it in to DataSet
     //Bind your GridView with that DataSourse.
  
    }
}


I hope it will help you.

Good luck.
 
Share this answer
 
v5
better use details view......
 
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