Home All Groups Group Topic Archive Search About

FormView/ItemTemplate - MultiView, Radio, & checkbox

Author
17 Mar 2006 6:43 PM
David Thielen
Hi;

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.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Author
20 Mar 2006 7:39 AM
Steven Cheng[MSFT]
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.)