Click here to Skip to main content
16,004,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i am cteate a grid view bound using eval metod from database values shows in grid view and i also taken edit, delete button mannually. now i want to open a new panel on click of edit button with rows id. how i can do this with grid view.
code is here as:
<asp:Panel ID="Pan_main2" runat="server" Width="100%">
        <asp:GridView runat="server" ID="grd"></asp:GridView>
            <asp:GridView runat="server" ID="gv" AutoGenerateColumns="false" PageSize="5"  
                GridLines="None" Width="80%"  align="center" 
               >
                <HeaderStyle BackColor="#84A8C9" />
                <AlternatingRowStyle BackColor="#F4FAFF" />
                <RowStyle BackColor="#DBECFB" />
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <font color="#F4FAFF"><b>Action</b></font>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox runat="server" ID="chkid" Width="16" />
                            <asp:Button runat="server" Text="Edit" CommandName="edit" />
                            <asp:Button runat="server" Text="del" CommandName="del" />
                        </ItemTemplate>
                        <ItemStyle Height="12%" Width="13%" />
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <font color="#F4FAFF"><b>Name</b></font>
                        </HeaderTemplate>
                        <ItemTemplate>
                             <font color="#034f94">&nbsp;&nbsp;
                                 <%--<asp:Label ID="lblName" runat="server" Text='<%#Eval("Course_name") %>' />--%>
                                 <asp:Literal ID="ltrl" runat="server" Text='<%#Eval("Course_name") %>'></asp:Literal>
                             </font>
                        </ItemTemplate>
                        <ItemStyle Height="12%" HorizontalAlign="Left" Width="28%" />
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <font color="#F4FAFF"><b>Duration</b></font>
                        </HeaderTemplate>
                        <ItemTemplate>
                             <font color="#034f94">&nbsp;&nbsp;
                                 <asp:Literal ID="lt_fees" runat="server" Text='<%#Eval("Course_duration") %>'></asp:Literal>
                             </font>
                        </ItemTemplate>
                        <ItemStyle Height="12%" HorizontalAlign="Left" Width="28%" />
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
                    
                </asp:Panel>


in .cs file i have code in try catch block with function and connection
MIDL
cmd.Connection.Open();
           gv.DataSource = cmd.ExecuteReader();
           gv.DataBind();

Thanks & REgards
Umesh Daiya
Posted
Updated 22-Feb-11 19:57pm
v2
Comments
nagendrathecoder 23-Feb-11 1:57am    
Edited for visibility.
Sunasara Imdadhusen 23-Feb-11 2:09am    
what dose it mean "open a new panel"?

Use gridview row command event

C#
Protected void ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
 if(e.CommandName=="Add")
 {
  //code to open new panel
 }
}

GridView.RowCommand Event[^]
 
Share this answer
 
Comments
UD(IA) 23-Feb-11 2:49am    
i use this code but now i got this problem

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.
m@dhu 23-Feb-11 3:03am    
Change to false in the page directive EnableEventValidation="false"
UD(IA) 23-Feb-11 2:49am    
thanks for reply
Have a look at these:
GridView Event Handling[^]
Using the GridView Events[^]
GridView Events[^]

In order to do any operation on edit/delete or so, just associate that operation with the related event handler as described in the article samples.
 
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