This is an example, but basically what you can do, instead of creating a control parameter, you can create a session parameter or something like that:
So, when you press the enter button, it will use the value of the text field or when changing the drop-down list, it will use the value of the drop-down list.
You may also have a radio button that allows the user to indicate where he wants this value.
<asp:DropDownList ID="ddl" runat="server" AutoPostBack="true" onselectedindexchanged="ddl_SelectedIndexChanged"></asp:DropDownList> <asp:TextBox ID="txt" runat="server"></asp:TextBox> <asp:Button runat="server" Text="ClickMe" ID="btnOne" OnClick="btnOne_Click"/> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"> <SelectParameters> <asp:SessionParameter SessionField="ObjectParameterName" /> </SelectParameters> </asp:ObjectDataSource>
Code for:
protected void ddl_SelectedIndexChanged(object sender, EventArgs e) { var ddl = (DropDownList)sender; Session["ObjectParameterName"] = ddl.SelectedValue; ObjectDataSource1.Select(); } protected void btnOne_Click(object sender, EventArgs e) { var ddl = (DropDownList)sender; Session["ObjectParameterName"] = txt.Text; ObjectDataSource1.Select(); }
CHANGE AFTER REPAIR
You can also, instead of assigning a parameter to the session field, simply set the objectdatasource parameter directly (deletion ban processing).
protected void ddl_SelectedIndexChanged(object sender, EventArgs e) { var ddl = (DropDownList)sender; ObjectDataSource1.SelectParameters.Add(new Parameter() {Name="Name",DefaultValue=ddl.SelectedValue }); }
source share