|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
FormView/ItemTemplate - MultiView, Radio, & checkboxHi;
I am trying to set up my ItemView inside a FormView. I have a couple of questions. 1) How should I display a radio button value. This is a view so they can't change it, but I'd like to display it that way. 2) Same question for a check box. 3) How should I display a multi-view? Which view is based on a value in the row's data. Hi Dave,
As for your 3 questions, here are some of my undertanding and suggestion: For Q1 and Q2, I think you can consider either make the radiobutton/checkbox disabled or use some client-side script to ignore the user's click event so that others can not modify it. e.g: ======================================== <ItemTemplate> <asp:RadioButton ID="rb1" Text='<%# Bind("CategoryName") %>' GroupName="tc" runat="server" Enabled="false" /> <asp:RadioButton ID="rb2" Text='<%# Bind("CategoryName") %>' GroupName="tc" runat="server" Enabled="false" /> <asp:CheckBox ID="cb1" runat="server" Text='<%# Bind("CategoryName") %>' OnPreRender="cb1_PreRender" /> </ItemTemplate> ======================================== protected void cb1_PreRender(object sender, EventArgs e) { ((CheckBox)sender).Attributes["onclick"] = "return false;"; } For Q3, I think the "DataBound" event of the FormView control should be helpful. We can add some code to do some modification on the controls' property according to the databound value. e.g: ======================== <ItemTemplate> ....................... <hr /> <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0"> <asp:View ID="view1" runat="server" > <asp:Label ID="Label1" runat="server" Text="View1"></asp:Label> </asp:View> <asp:View ID="view2" runat="server"> <asp:Label ID="Label2" runat="server" Text="View2"></asp:Label> </asp:View> </asp:MultiView> </ItemTemplate> </asp:FormView> ============================== protected void FormView1_DataBound(object sender, EventArgs e) { if (FormView1.CurrentMode == FormViewMode.ReadOnly) { MultiView mv = FormView1.Row.FindControl("MultiView1") as MultiView; mv.ActiveViewIndex = ((int)FormView1.DataKey.Value) % 2; } } Hope this helps. Regards, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.)
Are you sure? for delete in GridView
FormView vs create How to get CommandField and ButtonField in the toolbox? Binding TextBox paging control? GridView and DetailsView/FormView in seperate pages FormView sample that includes edit/delete? DataView, DataTable, or DataSet? Disable CommandField for some rows of data Creating Dynamic controls |
|||||||||||||||||||||||