日期:2014-05-20  浏览次数:20556 次

如何获得FormView1内的Label1控件?
源代码如下:
        <asp:FormView   ID= "FormView1 "   runat= "server "   DataKeyNames= "TitleID "   DataSourceID= "SqlDataSource1 "
                DefaultMode= "Insert ">
                <InsertItemTemplate>
                        CategoryID:&nbsp;
                        <asp:DropDownList   ID= "DropDownList1 "   runat= "server "   DataSourceID= "SqlDataSource2 "
                                DataTextField= "Desn "   DataValueField= "CategoryID "   SelectedValue= ' <%#   Bind( "CategoryID ")   %> '   AutoPostBack= "True ">
                        </asp:DropDownList>
                        <asp:Label   ID= "Label1 "   runat= "server "   Text= "Label "> </asp:Label> <br   />

想让label1显示DropDownList1的值,那我在CS里应怎么写??

------解决方案--------------------
FormView处于插入记录模式,Label1和DropDownList都在FormView中吧,可以这样用
DropDownList DropDownList1 = (DropDownList)FormView1.FindControl( "DropDownList1 ");
Label Label1 = (Label)FormView1.FindControl( "Label1 ");

Label1.Text=DropDownList1.selectedvalue;