Click here to Skip to main content
14,739,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using Repeater control and inside it I am using an image button. When I click on button, it opens a modal popup with some textfields. I want to know how can I make modal popup to edit a record of the repeater, i.e. when I open the modal popup, the text fields in it display the record of selected row of repeater.
The code of repeater is:
<asp:Repeater ID="rptuser" runat="server" DataSourceID="ObjectDataSource1">
      <td class="GridHeader"></td>
      <td  class="GridHeader">UserID:</td>
      <td class="GridHeader">FirstName:</td>
      <td class="GridHeader">LastName:</td>
      <td class="GridHeader">Designation:</td>
      <td  class="GridHeader">UserName:</td>
      <td class="GridHeader"></td>
      <td class="GridItems"><asp:ImageButton runat="server" ID="delbtn" ImageUrl="~/images/delete.gif" CommandName="del" CommandArgument='<%# Eval("UserId") %>'  ValidationGroup="ab" ToolTip="Delete User"  /></td>
       <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"UserId") %>'</td>
       <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"FirstName") %>'></td>
       <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"LastName") %></td>
       <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"Designation") %></td>
       <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"Username") %></td>
       <td class="GridItems"><asp:ImageButton ID="updbtn"  ValidationGroup="Av" runat="server" ImageUrl="~/images/update.jpg"   CommandName="upd" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"UserId") %>' /><ajx:ModalPopupExtender ID="mpe" runat="server"

 TargetControlId="updbtn" PopupControlID="ModalPanel" OkControlID="OKButton" BackgroundCssClass="mdl" /></td>

And code of content inside modal popup:
<asp:Panel ID="ModalPanel" runat="server" Width="500px" CssClass="ModalWindow">
 <td><asp:TextBox ID="txteditfname" runat="server" CssClass="tx_box"></asp:TextBox></td>
 <td><asp:TextBox ID="txteditlname" runat="server" CssClass="tx_box"></asp:TextBox></td>
 <td><asp:TextBox ID="txteditdesig" runat="server" CssClass="tx_box"></asp:TextBox></td>
 <td><asp:TextBox ID="txtedituname" runat="server" CssClass="tx_box"></asp:TextBox></td>
 <asp:Button ID="OKButton" runat="server" ValidationGroup="abv" Text="Close" />
Updated 14-Jan-11 0:38am
JF2015 14-Jan-11 5:39am
Edited to fix coe formatting.

A very simple approach :

On the button you can have two properties :

1. commandArgument //commandArgumsnt=<%#Eval("ID")%>
2. commandName  //commandName="Edit"

Now, at the RowCommand event of the repeater, you can check if e.CommandName="Edit"


Int32 ID=e.CommandArgument.ToInt32();

Now, on opening the model-up, you can fill the textboxes by fetching the data from database using this id, and update it too.

Note: I have written all the code without checking, so I may contain syntactical mistakes as this was top on my head.

Hope this would solve your problem. Feel free to ask for any issue.

I would think that using a grid would be easier, so maybe this will be of interest:[^].

Anyway, it shows a way to perform the data editing using a popup.

Espen Harlinn

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