dropdownlist, listbox and gridview

Hello all,

I'm working on a project which requires the implementation of a dropdownlist connected to a database, a listbox and a gridview. When the user makes a selection from the dropdownlist, I need a list of items to be shown in the listbox according to which option the user selects. Once the user chooses the item from the listbox and presses "go", I need a list records to be shown in a gridview. The information is all stored in a database. I'm able to populate the dropdownlist, but I'm currently stuck on next two parts.

 

Here is the code I have...

 

public partial class BulkExtractM : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        PopulateDDL();
    }


    protected void PopulateDDL()
    {

        CHHExtractBL_Impl blHHExtract = new CHHExtractBL_Impl();
        DataSet ds = null;
        ds = blHHExtract.GetContractArea("<Root><ContractorID>1</ContractorID></Root>");

        DropDownContractorArea.DataSource = ds.Tables[0];
        DropDownContractorArea.DataTextField = "CITYMAP_Description";
        DropDownContractorArea.DataValueField = "CITYMAP_ID";
        DropDownContractorArea.DataBind();
    }

 
AvinashKNAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

varungdCommented:
Change 'AutoPostback' property as true for dropdownlist.. Then write the codes inside the '
SelectedIndexChanged ' event of dropdown  like

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
// here write the code for binding listbox.. like dropdownlist..

}
and also use the same format for binding the gridview.
0
AvinashKNAuthor Commented:
Like this?

    protected void DropDownContractorArea_SelectedIndexChanged(object sender, EventArgs e)
    {
        SetZipCode(DropDownContractorArea.SelectedValue.Trim());
    }
0
varungdCommented:
Yes. u r in  correct way .....
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

varungdCommented:
One more thing is, in your downdownlist u must include 'OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
LIke ...

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
0
AvinashKNAuthor Commented:
So, how do I populate the listbox with data?

I used the following code but it's not working...

    private void SetZipCode(string strContractArea)
    {

        CHHExtractBL_Impl blHHExtract = new CHHExtractBL_Impl();
        DataSet ds = null;
        string inXML = "<Root><ContractArea>" + strContractArea + "</ContractArea>";
        inXML += "<ContractorID>" + Session["MITS_USER_ID"] + "</ContractorID></Root>";
        ds = blHHExtract.GetZipCode(inXML);
        ContractAreaZipCode.DataSource = ds;
        ContractAreaZipCode.DataBind();
0
varungdCommented:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownContractorArea_SelectedIndexChanged">
</asp:DropDownList>
0
varungdCommented:
U please insert a breakpoint inside the 'OnSelectedIndexChanged' event and check, that code is working or not and also check dataset contains any data..
This command u can use for taking the number of rows in that dataset

int c= ds.Tables[0].Rows.Count;
0
varungdCommented:
U know how to insert breakpoint?
0
AvinashKNAuthor Commented:
Yes. The code is working.
0
varungdCommented:
What abt dataset ?Its have the value?
0
AvinashKNAuthor Commented:
Where do I put that code?

int c= ds.Tables[0].Rows.Count;
0
varungdCommented:
After this line
ds = blHHExtract.GetZipCode(inXML);

 and give the breakpoint on below given line...

ContractAreaZipCode.DataSource = ds;
 
 And your code must be like this...
  ds = blHHExtract.GetZipCode(inXML);
        ContractAreaZipCode.DataSource = ds;
ContractAreaZipCode.DataTextField =ds.Tables[0].Columns["Column Name"] .ToString();
ContractAreaZipCode.DataValueField = ds.Tables[0].Columns["Column Name"].ToString(); ;
   ContractAreaZipCode.DataBind();
 
 
 
0
varungdCommented:

ds = blHHExtract.GetZipCode(inXML);
       ContractAreaZipCode.DataSource = ds;
int c= ds.Tables[0].Rows.Count;
 
ContractAreaZipCode.DataTextField =ds.Tables[0].Columns["Column Name"] .ToString();// Give break poing here.
ContractAreaZipCode.DataValueField = ds.Tables[0].Columns["Column Name"].ToString(); 
   ContractAreaZipCode.DataBind(); 
 
 

Open in new window

0
AvinashKNAuthor Commented:
Still not working. The listbox is not populating.

Thanks for your help.
0
varungdCommented:
Please use this code instead of ' int c= ds.Tables[0].Rows.Count;' and tell me the value of  'c'


int c = 100;
c= ds.Tables[0].Rows.Count
Response.Write(c);
0
AvinashKNAuthor Commented:
I don't know how to see the value of c.

Can I email you the file?
0
varungdCommented:
I can't  use the mail here. u do one thing comment or  remove all other lines inside that 'Selected index changed event' and use below give code and  then it will write the value in the browser.  If u cant do this attach that file.  One more thing list box is working only while change the dropdownlist items.

ds = blHHExtract.GetZipCode(inXML);
       ContractAreaZipCode.DataSource = ds;
int c = 100;
c = ds.Tables[0].Rows.Count;
Response.Write(c);

Open in new window

0
AvinashKNAuthor Commented:
The name 'ds' does not exist in the current context.

That's the error I'm getting.

I tried attaching the file, but aspx extension is not supported here.

So I uploaded it to rapidshare.

http://rapidshare.com/files/160821764/BulkExtractM_modified_.zip.html
0
varungdCommented:
try this .

DataSet ds = blHHExtract.GetZipCode(inXML);
       ContractAreaZipCode.DataSource = ds;
int c = 100;
c = ds.Tables[0].Rows.Count;
Response.Write(c);

Open in new window

0
varungdCommented:
Sorry I can't access that site..  I am at office now. Here we have some restrictions for accessing the site. . So please attach that file
0
AvinashKNAuthor Commented:
I tried attaching it but it says that aspx file extension inside archive is not supported. Can you email me your email address and I can send it to you through that?

akribhanidhi@svam.com

or do you have google talk?
0
varungdCommented:
U copy the contants of aspx file to the text file and attach that file before that u try this code..

DataSet ds = blHHExtract.GetZipCode(inXML);
       ContractAreaZipCode.DataSource = ds;
int c = 100;
c = ds.Tables[0].Rows.Count;
Response.Write(c);

Open in new window

0
AvinashKNAuthor Commented:
I tried that and I'm getting the following error:

The name 'blHHExtract' does not exist in the current context
0
AvinashKNAuthor Commented:
Attached file.
bulkextract.doc
0
varungdCommented:
please declare this 'blHHExtract' . I think it is the object of that class file including this function . GetZipCode()
try this

 

CHHExtractBL_Impl blHHExtract = new CHHExtractBL_Impl();
        DataSet ds = null;
        string inXML = "<Root><ContractArea>" + strContractArea + "</ContractArea>";
        inXML += "<ContractorID>" + Session["MITS_USER_ID"] + "</ContractorID></Root>";
        ds = blHHExtract.GetZipCode(inXML);
 
 ds = blHHExtract.GetZipCode(inXML);
       ContractAreaZipCode.DataSource = ds;
int c = 100;
c = ds.Tables[0].Rows.Count;
Response.Write(c);

Open in new window

0
AvinashKNAuthor Commented:
Still not working. Can't seem to figure out what the problem is and I'm a complete beginner.

Thanks for your help anyway.
0
varungdCommented:
U r not changing the property of dropdown list ' AutopostBack'
Try this instead of your current drop down and check that.
 

 <asp:DropDownList ID="DropDownContractorArea" runat="server" Width="218px" OnSelectedIndexChanged="DropDownContractorArea_SelectedIndexChanged" AutoPostBack="True">
 
                                                  </asp:DropDownList>

Open in new window

0
varungdCommented:
I u can't do that, find the attached file and use this
bulkextract.doc
0
AvinashKNAuthor Commented:
I'm getting this error:

System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."
  Source="App_Web_ydc-xgyj"
  StackTrace:
       at BulkExtractM.SetZipCode(String strContractArea) in c:\Documents and Settings\Administrator\Nov4UI\BulkExtractM.aspx.cs:line 53
       at BulkExtractM.DropDownContractorArea_SelectedIndexChanged(Object sender, EventArgs e) in c:\Documents and Settings\Administrator\Nov4UI\BulkExtractM.aspx.cs:line 38
       at System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)
       at System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent()
       at System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
       at System.Web.UI.Page.RaiseChangedEvents()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
0
varungdCommented:
I think problem is in this functin

blHHExtract.GetZipCode(inXML);   Check this function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AvinashKNAuthor Commented:
Yes. That is the problem.

Thanks for all the help.
0
varungdCommented:
Also Try this..

 
 

DataSet ds = new DataSet(); 
CHHExtractBL_Impl blHHExtract = new CHHExtractBL_Impl();
               string inXML = "<Root><ContractArea>" + strContractArea + "</ContractArea>";
        inXML += "<ContractorID>" + Session["MITS_USER_ID"] + "</ContractorID></Root>";
        ds = blHHExtract.GetZipCode(inXML);
 
 ds = blHHExtract.GetZipCode(inXML);
       ContractAreaZipCode.DataSource = ds;
int c = 100;
c = ds.Tables[0].Rows.Count;
Response.Write(c);

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.