首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎么获得FormView1内的Label1控件

2012-03-24 
如何获得FormView1内的Label1控件?源代码如下:asp:FormViewID FormView1 runat server DataKeyName

如何获得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;

热点排行