Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am using asp.net gridview with c#.net.
I am using Ajax modal up control to edit the values of Gridview in Popup window.
Here my problem is if I click on edit image in Gridview,the modal popup is displaying but the values of Gridview are not displaying in Modal popup.
I am binding Gridview with the Datasource from SQL Server.
Could anyone help me the edit button click code behind to display values from gridview to modal popup.

Below is my Gridview aspx.
C#
<asp:GridView ID="gvDetails" DataKeyNames="SNo" runat="server" 
                    AutoGenerateColumns="False" ShowFooter="true" HeaderStyle-Font-Bold="true" 
                    DataSourceID="SqlDataSource1" onrowcommand="gvDetails_RowCommand" 
                    CellPadding="4" GridLines="Horizontal" BackColor="White" 
                    BorderColor="#336666" BorderStyle="Double" BorderWidth="3px">
                    
                    <Columns>
                    <asp:BoundField DataField="SNo" HeaderText="S.No" InsertVisible="False" 
                       ReadOnly="True" SortExpression="SNo" />
                    <asp:TemplateField HeaderText="CurrencyName" HeaderStyle-HorizontalAlign="Left">
                        <EditItemTemplate>                        
                        <asp:TextBox ID="txtCurName" runat="server" Text='<%#Eval("CurrencyName") %>'/>
                        </EditItemTemplate>
                        <ItemTemplate>                        
                        <asp:Label ID="lblCurName" runat="server" Text='<%#Eval("CurrencyName") %>'/>
                        </ItemTemplate>
                        <FooterTemplate>
                        <asp:TextBox ID="txtftrCurName" runat="server"/>
                        <asp:RequiredFieldValidator ID="rfvCurName" runat="server" ControlToValidate="txtftrCurName" Text="*" ValidationGroup="validaiton"/>
                        </FooterTemplate> 
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="CurrencyCode" HeaderStyle-HorizontalAlign="Left">
                        <EditItemTemplate>
                        <asp:TextBox ID="txtCurCode" runat="server" Text='<%#Eval("CurrencyCode") %>'/>
                        </EditItemTemplate>
                        <ItemTemplate>
                        <asp:Label ID="lblCurCode" runat="server" Text='<%#Eval("CurrencyCode") %>'/>
                        </ItemTemplate>
                        <FooterTemplate>
                        <asp:TextBox ID="txtftrCurCode" runat="server"/>
                        <asp:RequiredFieldValidator ID="rfvCurCode" runat="server" ControlToValidate="txtftrCurCode" Text="*" ValidationGroup="validaiton"/>
                        </FooterTemplate> 
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="CurrencySymbol" HeaderStyle-HorizontalAlign="Left">
                        <EditItemTemplate>
                        <asp:TextBox ID="txtCurSymbol" runat="server" Text='<%#Eval("CurrencySymbol") %>'/>
                        </EditItemTemplate>
                        <ItemTemplate>
                        <asp:Label ID="lblCurSymbol" runat="server" Text='<%#Eval("CurrencySymbol") %>'/>
                        </ItemTemplate>
                        <FooterTemplate>
                        <asp:TextBox ID="txtftrCurSymbol" runat="server"/>
                        <asp:RequiredFieldValidator ID="rfvCurSymbol" runat="server" ControlToValidate="txtftrCurSymbol" Text="*" ValidationGroup="validaiton"/>
                        </FooterTemplate> 
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Status" HeaderStyle-HorizontalAlign="Left">
                        <EditItemTemplate>
                        <asp:TextBox ID="txtStatus" runat="server" Text='<%#Eval("Status") %>'/>
                        </EditItemTemplate>
                        <ItemTemplate>
                        <asp:Label ID="lblStatus" runat="server" Text='<%#Eval("Status") %>'/>
                        </ItemTemplate>
                        <FooterTemplate>
                        <asp:TextBox ID="txtftrStatus" runat="server"/>
                        <asp:RequiredFieldValidator ID="rfvStatus" runat="server" ControlToValidate="txtftrStatus" Text="*" ValidationGroup="validaiton"/>
                        </FooterTemplate>
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Actions" HeaderStyle-HorizontalAlign="Left">
                        <EditItemTemplate>
                        <asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="~/Images/update.jpg" ToolTip="Update" Height="20px" Width="20px" />
                        <asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="~/Images/Cancel.jpg" ToolTip="Cancel" Height="20px" Width="20px" />
                        </EditItemTemplate>
                        <ItemTemplate>
                        <asp:ImageButton ID="btnEdit" OnClick="imgbtn_Click" runat="server" ImageUrl="~/Images/Edit.jpg" ToolTip="Edit" Height="20px" Width="20px" />
                        <asp:ImageButton ID="imgbtnDelete" CommandName="Delete" Text="Edit" runat="server" ImageUrl="~/Images/delete.jpg" ToolTip="Delete" Height="20px" Width="20px" />
                        </ItemTemplate>
                        <FooterTemplate>                        
                        <asp:ImageButton ID="imgbtnAdd" runat="server" ImageUrl="~/Images/AddNewitem.jpg" CommandName="Insert" Width="30px" Height="30px" ToolTip="Add new User" ValidationGroup="validaiton" />
                        </FooterTemplate>
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:TemplateField>
                    </Columns>                    
              </asp:GridView>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
            <cc1:ModalPopupExtender ID="ModalPopupExtender1"  runat="server" BackgroundCssClass="modalBackground"
                TargetControlID="btnShowPopup" PopupControlID="pnlpopup" 
                CancelControlID="btnCancel"></cc1:ModalPopupExtender>
            <asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="269px" Width="400px" style="display:none">
            <table width="100%" style="border:Solid 3px; width:100%; height:100%" cellpadding="0" cellspacing="0">
            <tr>
            <td colspan="2" style=" height:10%; color:Green; font-weight:bold; font-size:larger" align="center">Update Currency</td>
            </tr>
            <tr>
            <td align="right">S.No : </td>
            <td><asp:TextBox ID="txtSNo" runat="server" ReadOnly="true"/></td>
            </tr>            
            <tr>
            <td align="right">Currency Name : </td>
            <td><asp:TextBox ID="txtCurName" runat="server"/></td>
            </tr>   
            <tr>
            <td align="right">Currency Code : </td>
            <td><asp:TextBox ID="txtCurCode" runat="server"/></td>
            </tr>
            <tr>
            <td align="right">Currency Symbol : </td>
            <td><asp:TextBox ID="txtCurSymbol" runat="server"/></td>
            </tr>                       
            <tr>
            <td></td>
            <td><asp:Button ID="btnUpdate" CommandName="Update" runat="server" Text="Update" onclick="btnUpdate_Click"/>
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
            </td>
            </tr>
            </table>
           </asp:Panel>

Thank you,
Palcordis
Posted
Updated 10-Aug-12 3:35am
v2
Comments
bbirajdar 10-Aug-12 9:29am    
You need to show the aspx code for ModalPopup extender and the code-behind for binding the gridview and for binding the Panel controls for Modal Popup which shows values for editing...
palcordis 10-Aug-12 9:36am    
I updated my question.I bind gridview using sqldatasource in aspx page only.Please have a look
bbirajdar 10-Aug-12 12:43pm    
What I can see from your code is that you have not written any code to bind the textboxes in the Panel

1 solution

you need to add the given tag on your page.
ASP.NET
<asp:toolkitscriptmanager id="toolScript1" runat="server" xmlns:asp="#unknown"></asp:toolkitscriptmanager>

and then you have to write the following code in
C#
protected void btnEdit_Click(object sender, ImageClickEventArgs e)
   {
       ImageButton btndetails = sender as ImageButton;
       GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
       txtSNo = grv.DataKeys[gvrow.RowIndex].Value.ToString();
       txtCurName.Text = gvrow.Cells[2].Text;
       txtCurCode.Text = gvrow.Cells[3].Text;
       txtCurSymbol.Text = gvrow.Cells[4].Text;
       this.ModalPopupExtender1.Show();
   }

hope, it will help you.
Best of Luck
 
Share this answer
 
Comments
palcordis 13-Aug-12 3:09am    
Thank you all,

This is my code behind to display Gridview values in popup,but popup opening without values.

protected void imgbtn_Click(object sender, ImageClickEventArgs e)
{
ImageButton btndetails = sender as ImageButton;
GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
txtSNo.Text = gvrow.Cells[1].Text;
txtCurName.Text = gvrow.Cells[2].Text;
txtCurCode.Text = gvrow.Cells[3].Text;
txtCurSymbol.Text = gvrow.Cells[4].Text;
this.ModalPopupExtender1.Show();

}
I dont know where I made wrong.Please help me...
_Raj sinha 13-Aug-12 4:07am    
As per your desgn page you are storing the SNo in data keys.
so insteda of:
txtSNo.Text = gvrow.Cells[1].Text;
you have to write this one:
txtSNo = grv.DataKeys[gvrow.RowIndex].Value.ToString();
try this it will work.

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