Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 29th, 2007, 07:30 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple Dropdown lists inside a datagrid

Hi,
   I am having 3 dropdown lists inside a datagrid , am using VS.NET 2005. I have defined 2 SQL datasources for the first 2 drop down lists and they are populated on page load. The 3rd drop down list is also associated with a SQl data source where the query expects an input parameter which is nothing but the 2nd drop down list value.

I have this set up by calling the method to pass the SQL Data source Select parameter on the 2nd dropdown list's selectedindexchanged method. But when the 2nd drop down list changes, all the rows of the 3rd drop down changes to the same values. ie., the select parameter that I am passing to populate the 3rd dropdown applies across all the rows. So if I change a value on the 2nd row drop down , then both the first row and second row changes



datagrid definition

<asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False" PageSize="5" AllowPaging="True" OnItemDataBound="DataGrid1_ItemDataBound" OnPageIndexChanged="DataGrid1_PageIndexChanged" OnItemCommand="DataGrid1_ItemCommand">
                        <Columns>
                            <asp:TemplateColumn HeaderText="Sales Org">
                                <ItemTemplate>
                                    <asp:dropdownlist id="ddlSalesOrg" runat="server" DataSourceID="SqlDataSourceSalesOrg" DataTextField="salesorg_desc" DataValueField="salesorg_code"></asp:dropdownlist>
                                    <asp:RequiredFieldValidator ID="vldSalesOrg" runat="server" ControlToValidate="ddlSalesOrg"
                                        ErrorMessage="Sales Org cannot be blank">!</asp:RequiredFieldValidator>
                                </ItemTemplate>
                            </asp:TemplateColumn>
                            <asp:TemplateColumn HeaderText="District">
                                <ItemTemplate>
                                    <asp:dropdownlist id="ddlDistrict" runat="server" DataSourceID="SqlDataSourceDistrict" DataTextField="district_name" DataValueField="district_code" AutoPostBack="True" OnSelectedIndexChanged="ddlDistrict_SelectedIndexC hanged"></asp:dropdownlist>
                                </ItemTemplate>
                            </asp:TemplateColumn>
                            <asp:TemplateColumn HeaderText="Sales Rep">
                                <ItemTemplate>
                                    <asp:dropdownlist id="ddlSalesRep" runat="server" DataSourceID="SqlDataSourceSalesRep" DataTextField="SalesRep_Name" DataValueField="SalesRep_Code"></asp:dropdownlist>
                                </ItemTemplate>
                                <FooterStyle HorizontalAlign="Right"></FooterStyle>
                                <FooterTemplate>
                                </FooterTemplate>
                            </asp:TemplateColumn>
                            <asp:TemplateColumn HeaderText="Delete">
                                <ItemTemplate>
                                    <asp:LinkButton id="DeleteRow" runat="server">X</asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateColumn>
                        </Columns>
                        <PagerStyle NextPageText="Next" PrevPageText="Previous" HorizontalAlign="Center" Mode="NumericPages"></PagerStyle>
                    </asp:datagrid>


Code Behind


 protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {
           dsRole.RoleRecordRow dataRow;
           dataRow = (dsRole.RoleRecordRow)(((DataRowView)e.Item.DataIt em).Row);
           DropDownList SalesOrg = (DropDownList)(e.Item.FindControl("ddlSalesOrg"));
           dataRow.SalesOrg = SalesOrg.SelectedItem.Value.Trim();
           DropDownList ddlDistrict = (DropDownList)e.Item.FindControl("ddlDistrict");
           dataRow.District = ddlDistrict.SelectedItem.Value.Trim();
           DropDownList ddlSalesRep = (DropDownList)e.Item.FindControl("ddlSalesRep");
           // check if the dropdown is empty, else show the value;
           if (ddlSalesRep != null && ddlSalesRep.Items.Count != 0 && ddlSalesRep.SelectedItem != null)
           {
               dataRow.SalesRep = ddlSalesRep.SelectedItem.Value.Trim();
           }

        }

  protected void ddlDistrict_SelectedIndexChanged(object sender, EventArgs e)
    {
       string District_code = "";
       foreach (DataGridItem gridRow in DataGrid1.Items)
       {
           DropDownList ddlDistrict = (DropDownList)(gridRow.FindControl("ddlDistrict")) ;
           DropDownList ddlSalesRep = (DropDownList)(gridRow.FindControl("ddlSalesRep")) ;

           District_code = ddlDistrict.SelectedItem.Value;
           Response.Write(" district code : " + District_code);


           if (District_code.Trim() != "")
           {
               SqlDataSourceSalesRep.SelectParameters.Clear();
               ddlSalesRep.DataSourceID = "SqlDataSourceSalesRep";
               ddlSalesRep.DataTextField = "SalesRep_Name";
               ddlSalesRep.DataValueField = "SalesRep_Code";
               SqlDataSourceSalesRep.SelectParameters.Add("distri ct_code", District_code);
               District_code = "";

           }
           else {
               ddlSalesRep.Items.Clear();
           }

       }

    }
So on the first row,if the district ddl changes to say "a" then the salesrep ddl should show only "a" district items.

On the second row, if district ddl is set to "b" then the salesrep ddl should show only "b" district items. but the way I do, when I change the second row to "b", then both first and second row shows only the "b" items for the sales rep dropdown list.

I believe that the data_itembound method should be used along with the dropdown Selected Index changed method to achieve what I want, but I dont know how I would do that. Tried the hidden field but again having the same issue with the row binding within the datagrid.

Can anyone please help me? I am running out of options.

Regards,
Gayathri.
Reply With Quote
  #2 (permalink)  
Old October 5th, 2007, 08:26 AM
Registered User
 
Join Date: Feb 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai, have to got the solution for this problem. if yes, send me the solution. i have the same problem.

Reply With Quote
  #3 (permalink)  
Old October 24th, 2007, 04:06 PM
Registered User
 
Join Date: Oct 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by elavarasum
 Hai, have to got the solution for this problem. if yes, send me the solution. i have the same problem.
I have a solution but it is not the complete solution. I created a RenderContents class to render the DropDownList. In the RenderContents class you can custom how you want your string to format. But the problem is the space which is using to format the string. If the font size change or using different font the for format is not align because of the space is not changing the size. As long as you have set the font and the font size for the DropDownList. It will work fine.

Reply With Quote
  #4 (permalink)  
Old October 24th, 2007, 04:09 PM
Registered User
 
Join Date: Oct 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by elavarasum
 Hai, have to got the solution for this problem. if yes, send me the solution. i have the same problem.
I have a solution but it is not the complete solution. I created a RenderContents class to render the DropDownList. In the RenderContents class you can custom how you want your string to format. But the problem is the space which is using to format the string. If the font size change or using different font the format is not align because of the space is not changing its size. As long as you have set the font and the font size for the DropDownList. It will work fine.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked Dropdown Lists contagiouss_blue Beginning VB 6 1 June 8th, 2005 10:35 AM
dependent dropdown lists vivshah VS.NET 2002/2003 1 March 29th, 2004 05:25 PM
2 tables and 2 dropdown lists collie Classic ASP Databases 0 October 20th, 2003 07:20 AM
Can't Populate Multiple Dropdown Lists with DSO nick8245 Javascript 4 September 24th, 2003 08:55 AM



All times are GMT -4. The time now is 08:19 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.