开发者

Bring up input form on same page with dropdownlist?

开发者 https://www.devze.com 2023-02-28 16:54 出处:网络
I\'m brand new at this, using vs2010 with asp.net and c#, and I\'m trying to use a button click event to display forms on my \"Add Product\" page (the forms will be textbox/label based for inputting d

I'm brand new at this, using vs2010 with asp.net and c#, and I'm trying to use a button click event to display forms on my "Add Product" page (the forms will be textbox/label based for inputting data), using items from a dropdownlist of products. Which methods are available/is there a 'best practice' for t开发者_如何转开发his sort of thing? I've been fooling around with an if (Dropdownlist.SelectedIndexChanged) statement, but I'm not quite clear on why the syntax requires the SelectedIndexChanged method to preclude a += or -=. Thoughts?


The SelectedIndexChanged method has the += because you are adding an event handler to a specific elements event. Is the button you click on the Add Product page? If so for the OnClick event you could just set your form details based on the DropDownList SelectedItem or SelectedIndex. You may also need to wrap that panel in an UpdatePanel so that it can update visibility without reloading the whole page.

<asp:UpdatePanel ID="updateFormPanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>

<asp:Label ID="lblName" runat="server" Text="" />
<asp:TextBox ID="txtDetails" runat="server" Text="" />
//More TextBox's or whatever you want

</ContentTemplate>
</asp:UpdatePanel?
<asp:DropDownList ID="ddlProductCategory" runat="server" />
<asp:Button ID="btnAddProduct" runat="server" OnClick="AddProduct_Click" Text="Add Product" />

//Code File Behind
protected void AddProduct_Click(Object sender, EventArgs e)
{
    lblName.Text = ddlProductCategory.SelectedItem.Text;
    txtDetails.Text = ddlProductCategory.SelectedItem.Value;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消