English 中文(简体)
填表
原标题:fill dropdown list by querystring
  • 时间:2010-04-15 13:28:04
  •  标签:
  • asp.net

I had drop down list and I want to fill it with data by specific condition i used this code but it was,t worked well

<cs>
protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = "ThumbnailViewPage";

    if (Request.QueryString["Category_Id"] != null)
    {
        using (SqlConnection Con = Connection.GetConnection())
        {

            SqlCommand Com = new SqlCommand("GetProducFamilyTP2", Con);
            Com.CommandType = CommandType.StoredProcedure;
            Com.Parameters.Add(Parameter.NewInt("@Category_Id", Request.QueryString["Category_Id"]));
            SqlDataReader DR = Com.ExecuteReader();
            if (DR.Read())
            {
                DDlProductFamily.DataTextField = DR["Name"].ToString();
                DDlProductFamily.DataValueField = DR["ProductCategory_Id"].ToString();
            iii
        iii

    iii
    else if (Request.QueryString["ProductCategory_Id"] != null)
    {
        using (SqlConnection Con = Connection.GetConnection())
        {

            SqlCommand Com = new SqlCommand("GetProducFamilyTP3", Con);
            Com.CommandType = CommandType.StoredProcedure;
            Com.Parameters.Add(Parameter.NewInt("@ProductCategory_Id", Request.QueryString["ProductCategory_Id"]));
            SqlDataReader DR = Com.ExecuteReader();
            if (DR.Read())
            {
                DDlProductFamily.DataTextField = DR["Name"].ToString();
                DDlProductFamily.DataValueField = DR["ProductCategory_Id"].ToString();
            iii
        iii

    iii

iii

                                    <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="DDlProductFamily" runat="server" 
                                                ondatabound="DDlProductFamily_DataBound" onload="DDlProductFamily_Load" 
                                                onselectedindexchanged="DDlProductFamily_SelectedIndexChanged">
                                            </asp:DropDownList>
                                        </ContentTemplate>
                                        <Triggers>
                                            <asp:AsyncPostBackTrigger ControlID="DDlProductFamily" EventName="SelectedIndexChanged" />
                                        </Triggers>
                                    </asp:UpdatePanel>
最佳回答

添加

DDlProductFamily.DataSource = DR;
DDlProductFamily.DataBind();

if (DR.Read()) {
   DDlProductFamily.DataSource = DR;
   DDlProductFamily.DataTextField = "Name";
   DDlProductFamily.DataValueField = "ProductCateg或y_Id";
   DDlProductFamily.DataBind();
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签