Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i have a gridview
in my grid view is this controls:
label ,button,image
i want ,when click on button of a cell of grid view
go to webform2 ,and show more info of that row(cell) of grid view
example :click on button(text="more info") and redirect to other page and view more info about that row of grid view that clicked.
plz give me a c# code
Posted
Updated 25-May-12 10:11am
v2
Comments
Technoses 26-May-12 1:12am    
<asp:TemplateField>
<asp:LinkButton style="width:70px;" ID="btnAct" Text='More Info' runat="server" OnClientClick='<%# "gomore(" + Eval("Id").ToString() + "); return false;" %>' />
Technoses 26-May-12 1:13am    
???
sadegh_rusta 28-May-12 12:37pm    
i want c#code
Technoses 29-May-12 12:26pm    
this code is to be written on aspx page not in c#

you can use ASP:Template Field in Gridview
Which works fast then other process like
Not Necessary to call Row_DataBound event
which run for each for of grid
if grid has 1000 of rows then process goes slow..

How to use

ASP.NET
<asp:templatefield xmlns:asp="#unknown">
               <asp:linkbutton style="width:70px;" id="btnAct" text="More Info" runat="server" onclientclick="<%# "gomore(" + Eval("Id").ToString() + "); return false;" %>" />
               </asp:templatefield>



and after grid you can add a javascript function i.e.

JavaScript
function gomore(id)
{
    window.location.href="viewmore.aspx?"+id;
}


try it.
if any problem then comment...

if your problem got solved then mark it as solution ..
 
Share this answer
 
Comments
sadegh_rusta 28-May-12 12:40pm    
dont know
its just sample

XML
<asp:GridView ID="gvUserdetails" runat="server" AutoGenerateColumns="False" OnRowCommand="gvUserdetails_RowCommand">
        <Columns>
            <asp:TemplateField HeaderText="DELETE">
                <ItemTemplate>
                    <asp:Button ID="btn1" runat="server" Text="Click for Details" CommandName="Show" CommandArgument='<%#Container.DataItemIndex %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="email">
                <ItemTemplate>
            <asp:Label ID="lblemail" runat="server" Text='<%#Bind("Email") %>' />
                </ItemTemplate>
                </asp:TemplateField>

</Columns>
       </asp:GridView>



and in .cs file code should be like this

C#
protected void gvUserdetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
   if (e.CommandName == "Delete")
   {
    int index=Convert.ToInt32(e.CommandArgument);
    Response.Redirect("required page url");
   }
}
 
Share this answer
 
v2
Comments
sadegh_rusta 28-May-12 14:53pm    
i do it
but in my project is error after click on button

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

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