Adding to that: The nice inbetween of GridView and Repeater is ListView. It has freedom of expression like Repeater, but also offers support for Select and Edit, like GridView.
Validation Controls can be added. But for GridView you will need to use TemplateField to do it. In ListView it's easy, as it already does everything with templates.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
ciupazMI
Member
140 Points
172 Posts
Repeater open in edit mode
Mar 01, 2012 07:34 PM|LINK
Hi, I have a Repeater that when I got the page it opens in edit mode. How can I force to show it at first in Select mode only?
Here is my html code:
<asp:Repeater ID="rptBudget" DataSourceID="srcBudget" runat="server" OnItemCommand="rptBudget_ItemCommand" OnItemDataBound="rptBudget_ItemDataBound" OnDataBinding="rptBudget_DataBinding"> <HeaderTemplate> <table> <tr> <th> Utente </th> <th> Budget </th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <asp:TextBox ID="txtUtente" Width="200px" Text='<%#Eval("Utente")%>' runat="server" /> </td> <td> <asp:TextBox ID="txtBudget" Width="150px" Text='<%#Eval("Budget")%>' runat="server" /> </td> <td> <asp:LinkButton ID="lnkUpdate" CommandName="Update" Text="Update" runat="server" /> | <asp:LinkButton ID="lnkDelete" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure?');" runat="server" /> </td> </tr> </ItemTemplate> <FooterTemplate> <tr> <td> <asp:TextBox ID="txtUtente" runat="server" /> </td> <td> <asp:TextBox ID="txtBudget" runat="server" /> </td> <td> <asp:LinkButton ID="lnkInsert" CommandName="Insert" Text="Insert" runat="server" /> </td> </tr> </table> </FooterTemplate> </asp:Repeater> <asp:SqlDataSource ID="srcBudget" ConnectionString="<%$ ConnectionStrings:UnicreditConnection %>" SelectCommand="SELECT IdGestioneBudget,Utente,Budget,DataModifica FROM dbo.GestioneBudget" UpdateCommand="UPDATE GestioneBudget SET Budget=@Budget WHERE IdGestionebudget=@IdGestionebudget" InsertCommand="INSERT GestioneBudget (Utente,Budget) VALUES (@Utente,@Budget)" DeleteCommand="DELETE dbo.GestioneBudget WHERE IdGestioneBudget=@IdGestioneBudget" runat="server"> <UpdateParameters> <asp:Parameter Name="IdGestioneBudget" /> <asp:Parameter Name="Utente" Type="String" /> <asp:Parameter Name="Budget" DbType="Decimal" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Utente" Type="String" /> <asp:Parameter Name="Budget" DbType="Decimal" /> </InsertParameters> <DeleteParameters> <asp:Parameter Name="IdGestioneBudget" /> </DeleteParameters> </asp:SqlDataSource>using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace UnicreditSponsorship.Amministrazione { public partial class GestioneBudget : System.Web.UI.Page { string DataKeyName = "IdGestioneBudget"; protected void Page_Load(object sender, EventArgs e) { } Hashtable Keys { get { if (ViewState["Keys"] == null) ViewState["Keys"] = new Hashtable(); return (Hashtable)ViewState["Keys"]; } } protected void rptBudget_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Keys.Add(e.Item.ItemIndex, DataBinder.Eval(e.Item.DataItem, "IdGestioneBudget")); } } protected void rptBudget_DataBinding(object sender, EventArgs e) { Keys.Clear(); } protected void rptBudget_ItemCommand(object source, RepeaterCommandEventArgs e) { switch (e.CommandName) { case "Update": UpdateBudget(e); break; case "Insert": InsertBudget(e); break; case "Delete": DeleteBudget(e); break; } } void InsertBudget(RepeaterCommandEventArgs e) { TextBox txtUtente = (TextBox)e.Item.FindControl("txtUtente"); TextBox txtBudget = (TextBox)e.Item.FindControl("txtBudget"); // Set the DataSource parameters srcBudget.InsertParameters["Utente"].DefaultValue = txtUtente.Text; srcBudget.InsertParameters["Budget"].DefaultValue = txtBudget.Text; // Fire the InsertCommand srcBudget.Insert(); } void UpdateBudget(RepeaterCommandEventArgs e) { TextBox txtUtente = (TextBox)e.Item.FindControl("txtUtente"); TextBox txtBudget = (TextBox)e.Item.FindControl("txtBudget"); // Set the DataSource parameters srcBudget.UpdateParameters["IdGestioneBudget"].DefaultValue = Keys[e.Item.ItemIndex].ToString(); srcBudget.UpdateParameters["Utente"].DefaultValue = txtUtente.Text; srcBudget.UpdateParameters["Budget"].DefaultValue = Convert.ToDecimal(txtBudget.Text).ToString(); // Fire the UpdateCommand srcBudget.Update(); } void DeleteBudget(RepeaterCommandEventArgs e) { // Set the DataSource parameters srcBudget.DeleteParameters["IdGestioneBudget"].DefaultValue = Keys[e.Item.ItemIndex].ToString(); // Fire the DeleteCommand srcBudget.Delete(); } } }Cheng Bao
Member
246 Points
145 Posts
Re: Repeater open in edit mode
Mar 01, 2012 07:37 PM|LINK
Repeater doesn't have edit mode nor select mode
ciupazMI
Member
140 Points
172 Posts
Re: Repeater open in edit mode
Mar 01, 2012 07:38 PM|LINK
So what I have to change to get the user click on a button prior to edit a value?
Cheng Bao
Member
246 Points
145 Posts
Re: Repeater open in edit mode
Mar 01, 2012 10:38 PM|LINK
The simpler way is use GridView.
otherwise you need to make "Update" and "Delete" button visible = false by default.
Add "Edit" button.
on edit button click event, make Edit button invisible, but update and delete button visible.
You may also need toggle the Textbox.Enable during the edit button event.
ciupazMI
Member
140 Points
172 Posts
Re: Repeater open in edit mode
Mar 02, 2012 01:29 PM|LINK
Hi Cheng, is it possible to add validation controls during editing values?
Luigi
superguppie
All-Star
48225 Points
8679 Posts
Re: Repeater open in edit mode
Mar 02, 2012 01:40 PM|LINK
Adding to that: The nice inbetween of GridView and Repeater is ListView. It has freedom of expression like Repeater, but also offers support for Select and Edit, like GridView.
Validation Controls can be added. But for GridView you will need to use TemplateField to do it. In ListView it's easy, as it already does everything with templates.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
daisydain
Member
222 Points
51 Posts
Re: Repeater open in edit mode
Mar 02, 2012 01:44 PM|LINK
Hello,
I also think List view will be ideal for you. Follow the links below.
http://www.youtube.com/watch?v=rnZ-ah57-6M
http://www.codeproject.com/Articles/128878/Sample-Code-to-Add-Edit-and-Delete-Rows-in-a-NET-W
basheerkal
Star
10672 Points
2426 Posts
Re: Repeater open in edit mode
Mar 02, 2012 01:45 PM|LINK
Yes, In editItem Templates You can add validation control/any control
B
(Talk less..Work more)
ciupazMI
Member
140 Points
172 Posts
Re: Repeater open in edit mode
Mar 02, 2012 01:48 PM|LINK
Do you have a tutorial to learn ListView?
ciupazMI
Member
140 Points
172 Posts
Re: Repeater open in edit mode
Mar 02, 2012 01:50 PM|LINK
Ah ok, I've seen the links :-)