在asp.net中,有时webcontrol需要引用另一个webcontrol,例如gridview需要它将绑定到的数据源对象的id。
我的webcontrol属性是一个字符串(我要引用的webcontrol的id)。如何根据此ID访问实际的webcontrol?
答案 0 :(得分:1)
this.FindControl()
http://msdn.microsoft.com/en-us/library/system.web.ui.control.findcontrol(v=VS.80).aspx
答案 1 :(得分:0)
以下是绑定到ObjectDataSource的GridView示例,其中ObjectDataSource绑定到参数的DropDownList。这应该可以帮到你。
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataSourceID="CustomerObjectDataSource"
DataKeyNames="CustomerID"
AllowPaging="True"
AllowSorting="True" AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True" AutoGenerateSelectButton="True"
onrowdeleted="GridView1_RowDeleted" onrowupdated="GridView1_RowUpdated">
<Columns>
...
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="CustomerObjectDataSource" runat="server"
EnablePaging="True"
MaximumRowsParameterName="totalRows"
StartRowIndexParameterName="firstRow"
TypeName="Northwind.Business.CustomerSource"
DataObjectTypeName="Northwind.Business.CustomerDTO"
SelectMethod="Load"
UpdateMethod="Save"
InsertMethod="Insert"
DeleteMethod="Delete"
SelectCountMethod="CustomerCount"
SortParameterName="sortExpression">
<SelectParameters>
<asp:ControlParameter ControlID="ddlRegion" Name="region"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:ObjectDataSource>