In ASP.NET, we like using "child" SqlDataSource inside a bound grid server control (Girdview or ListView).
I've been using this FindControl()
approach for years:
C# Codebehind:
protected void gridviewItems_RowDataBound(object sender, GridViewRowEventArgs e)
{
Label labelItemId = (Label)e.Row.FindControl("labelItemId");
}
or like this:
protected void buttonSend_Click(object sender, EventArgs e)
{
Label labelItemId = (Label)((Control)sender).NamingContainer.FindControl("labelItemId");
}
Nothing wrong with it, but I'm quite tired of it and maybe there's a way to do this in .aspx markup?
Something like:
<asp:DropDownList
ID="dropdownItems"
runat="server"
DataSource=<% this.NamingContainer.FindControl("slqdatasourceItems") %>
DataTextField="ItemName"
DataValueField="ItemId" />
Is this possible?