buttons on asp.net 2010 controls
-
When working with a C#asp.net 2010 web forms, I am wondering if you can take the 'buttons' out of a control and place them somewhere else on the webform and still have them work? I would want those buttons to still refer to the asp.net control that they were originally associated with? I am referring to buttons like insert, delete, and update. In particular I am asking that question about the listview, formview, or detailview control? If this is possible, I am wondering if you can tell how how to accomplish this task and/or point me to a url that I can use as a reference to complete this task? In addition when working with the buttons within the web form application and preferably not within the asp.net control, can I perform other programming that needs to occur? If so, can you tell point how this would be accomplished? Would I need to put the code in a certain method like a page_load,pre_init, a certain click event?
-
When working with a C#asp.net 2010 web forms, I am wondering if you can take the 'buttons' out of a control and place them somewhere else on the webform and still have them work? I would want those buttons to still refer to the asp.net control that they were originally associated with? I am referring to buttons like insert, delete, and update. In particular I am asking that question about the listview, formview, or detailview control? If this is possible, I am wondering if you can tell how how to accomplish this task and/or point me to a url that I can use as a reference to complete this task? In addition when working with the buttons within the web form application and preferably not within the asp.net control, can I perform other programming that needs to occur? If so, can you tell point how this would be accomplished? Would I need to put the code in a certain method like a page_load,pre_init, a certain click event?
if i understand, you want to preform update, insert, delete functions from other location rather than inside common asp.net grid controls like ListView, FormView, DetailsView... it can be done easily. you just need to call function you want to preform for target control. this is example how to call Update function for FormView outside of FormView
<asp:FormView runat="server" ID="fv" DefaultMode="Edit" DataKeyNames="id" OnItemUpdating="fv_ItemUpdating">
<EditItemTemplate>
<asp:TextBox runat="server" ID="tb" Text='<%#Bind("name") %>' />
<asp:Button runat="server" ID="btn" Text="Edit Inside" CommandName="Update" />
</EditItemTemplate>
</asp:FormView><asp:Button runat="server" ID="btn" Text="Edit Outside" OnClick="EditOutside" />
public System.Data.DataTable SomeData() { System.Data.DataTable temp = new System.Data.DataTable(); temp.Columns.Add("id"); temp.Columns.Add("name"); System.Data.DataRow dr = temp.NewRow(); dr\["id"\] = 1; dr\["name"\] = "somebody"; temp.Rows.Add(dr); dr = temp.NewRow(); dr\["id"\] = 2; dr\["name"\] = "someone"; temp.Rows.Add(dr); return temp; } protected void Page\_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { fv.DataSource = SomeData(); fv.DataBind(); } } public void fv\_ItemUpdating(object sender, FormViewUpdateEventArgs e) { string txtValue = (fv.FindControl("tb") as TextBox).Text; } public void EditOutside(object sender, EventArgs e) { fv.UpdateItem(false); }
-
if i understand, you want to preform update, insert, delete functions from other location rather than inside common asp.net grid controls like ListView, FormView, DetailsView... it can be done easily. you just need to call function you want to preform for target control. this is example how to call Update function for FormView outside of FormView
<asp:FormView runat="server" ID="fv" DefaultMode="Edit" DataKeyNames="id" OnItemUpdating="fv_ItemUpdating">
<EditItemTemplate>
<asp:TextBox runat="server" ID="tb" Text='<%#Bind("name") %>' />
<asp:Button runat="server" ID="btn" Text="Edit Inside" CommandName="Update" />
</EditItemTemplate>
</asp:FormView><asp:Button runat="server" ID="btn" Text="Edit Outside" OnClick="EditOutside" />
public System.Data.DataTable SomeData() { System.Data.DataTable temp = new System.Data.DataTable(); temp.Columns.Add("id"); temp.Columns.Add("name"); System.Data.DataRow dr = temp.NewRow(); dr\["id"\] = 1; dr\["name"\] = "somebody"; temp.Rows.Add(dr); dr = temp.NewRow(); dr\["id"\] = 2; dr\["name"\] = "someone"; temp.Rows.Add(dr); return temp; } protected void Page\_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { fv.DataSource = SomeData(); fv.DataBind(); } } public void fv\_ItemUpdating(object sender, FormViewUpdateEventArgs e) { string txtValue = (fv.FindControl("tb") as TextBox).Text; } public void EditOutside(object sender, EventArgs e) { fv.UpdateItem(false); }
Thanks! that is exactly what I want to do!