In asp.net sometimes a webcontrol needs to reference another webcontrol such as the gridview needs the id of the datasource ob开发者_如何学Pythonject that it will bind to.
I have a property of my webcontrol that is a string (the id of the webcontrol I want to reference). How do I access the actual webcontrol based on this id?
this.FindControl()
http://msdn.microsoft.com/en-us/library/system.web.ui.control.findcontrol(v=VS.80).aspx
Here's a sample of a GridView bound to an ObjectDataSource, with the ObjectDataSource binding to a DropDownList for a parameter. This should get you started.
<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>
精彩评论