[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1813
  • Last Modified:

Being able to choose to create 2 or 1 Dundas chart depending on the click value in a Datalist

I have a DataList when clicked creates a Dundas chart on the same page. Depending on the item clicked in the Dundas chart, how would I create 2 charts, or one chart?

Thanks
0
djshohit
Asked:
djshohit
  • 56
  • 37
1 Solution
 
djshohitAuthor Commented:
Here's the code I am working with.
<asp:DataList ID="DataList1" runat="server" DataKeyField="KM_ReportCountry" DataSourceID="SqlDataSource1">
            <ItemTemplate>
                        <asp:HyperLink ID="lnkTable" runat="server" NavigateUrl='<%# "~/Default.aspx?reportName=" + DataBinder.Eval(Container.DataItem, "reportname") + "&xval1=" + DataBinder.Eval(Container.DataItem, "xaxis1") + "&yval1=" + DataBinder.Eval(Container.DataItem, "yaxis1")  %>'>
                        <%# DataBinder.Eval(Container.DataItem,"report") %>
        </asp:HyperLink>
 
 
            </ItemTemplate>
        </asp:DataList><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Global KPIConnectionString %>"
        
                    SelectCommand="procGetReports" SelectCommandType="StoredProcedure">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="CountryListDropDown" Name="Country" 
                            PropertyName="SelectedValue" Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>
 
<br />
               
                <br />
            </td>
            <td>
                <dcwc:Chart ID="Chart1" runat="server" Height="423px" Palette="Pastel" 
                    Width="773px">
                    <Legends>
                        <dcwc:Legend Name="Default">
                        </dcwc:Legend>
                    </Legends>
                    <Series>
                        <dcwc:Series BorderColor="64, 64, 64" Name="Series1" ShadowOffset="1">
                        </dcwc:Series>
                        <dcwc:Series BorderColor="64, 64, 64" Name="Series2" ShadowOffset="1">
                        </dcwc:Series>
                    </Series>
                    <ChartAreas>
                        <dcwc:ChartArea Name="Default">
                        </dcwc:ChartArea>
                    </ChartAreas>
                </dcwc:Chart>
            </td>
        </tr>
    </table>
 
 
----------------------- C# Code
 
protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["reportName"] != null)
        {
            //create the datatable
            DataTable dt = new DataTable();
            //string connectionString = ConfigurationManager.ConnectionStrings["qeConnectionString1"].ConnectionString;
           // string connection = System.Configuration.ConfigurationManager.ConnectionStrings["Global KPIConnectionString"].ConnectionString;
           SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["Global KPIConnectionString"]);
           connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Global KPIConnectionString"].ConnectionString;
            connection.Open();
 
            SqlCommand sqlCmd = new SqlCommand("SELECT * FROM " + Request.QueryString["reportName"].ToString(), connection);
            SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
            sqlDa.Fill(dt);
 
 
            //bind to dundas
            Chart1.DataSource = dt;
            Chart1.DataBind();
 
            Chart1.Series.Add("Totals");
            Chart1.Series["Totals"].ValueMemberX = Request.QueryString["xval1"].ToString();
            Chart1.Series["Totals"].ValueMembersY = Request.QueryString["yval1"].ToString();
 
        }
    }

Open in new window

0
 
clintfieldCommented:
I think we first need to be sure that we include the other x and y values in your query string.  Right now, we only have xval1 and yval1.  You should add xval2 and yval2....which will come from your sproc result set.
Am I write in assuming that the second chart uses the same table for data, but it charts them on a different x and y?  That way you have two charts with the same data, but two ways of looking at it?
 
0
 
djshohitAuthor Commented:
I think I got the query string to get in the two values for the second table. The table only maps to the column names in the other tables (from where we are getting the actual data to map the graphs).

My problem is that in some cases, there are no x2 and y2 values, in which case you need only 1 graph instead of two.

P.S. I also noted that in the query string, the column names of the table (which I have as XAxis1, YAxis1, etc) dont have to be case sensitive. Thats a first I have seen.
ItemTemplate>
                        <asp:HyperLink ID="lnkTable" runat="server" NavigateUrl='<%# "~/Default.aspx?reportName=" + DataBinder.Eval(Container.DataItem, "ReportName") + "&xval1=" + DataBinder.Eval(Container.DataItem, "XAxis1") + "&yval1=" + DataBinder.Eval(Container.DataItem, "YAxis1")+ "&xval2=" + DataBinder.Eval(Container.DataItem, "XAxis2") + "&yval2=" + DataBinder.Eval(Container.DataItem, "YAxis2") %>'>
                        <%# DataBinder.Eval(Container.DataItem,"Report") %>
                        
        </asp:HyperLink>
 
 
            </ItemTemplate>

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
djshohitAuthor Commented:
Am I write in assuming that the second chart uses the same table for data, but it charts them on a "different x and y?  That way you have two charts with the same data, but two ways of looking at it?"

The two charts have data values from the same table but different columns. So there are two different columns that are present in the same table for two different charts. But they both have ths same x axis (the value it is being compared to), which is months.
0
 
djshohitAuthor Commented:
I hope this isnt too complicated. It should be pretty simple for you though :). Let me know if you have any questions :D. And again, thank you for your help.
0
 
clintfieldCommented:
If you dont have values for x2 and y2, then its easy to tell that you wont need to do a second graph.  We can figure this out easily from our dataset.
if(dt.Rows[0]["Xaxis2"] != System.DBNull.Value){
Chart2.Visible = true;
//bind second dundas chart with x2 and y2.
}
I havent really done this, but I would think that you should create the two dundas charts and set their visible properties to false.  Then when you find the appropriate x and y vals....set them to visible and bind.  Make sense?
0
 
clintfieldCommented:
Whoops...been a long day.  Dont check the datatable...check the querystring.  So it should be:
if(Request.QueryString["xval2"] != null){
//visible = true;
//bind chart2
}
0
 
clintfieldCommented:
I noticed your question asked about binding the chart.  Are you having issues with getting the datatable to bind, like we have in the codebehind?
            Chart1.DataSource = dt;
            Chart1.DataBind();

            Chart1.Series.Add("Totals");
            Chart1.Series["Totals"].ValueMemberX = Request.QueryString["xval1"].ToString();
            Chart1.Series["Totals"].ValueMembersY = Request.QueryString["yval1"].ToString();
 

0
 
djshohitAuthor Commented:
Let me try that out!
0
 
djshohitAuthor Commented:
Umm. If I have 2 charts, I will need 2 areas to bind it. Could you help me out with some code to create two areas?
0
 
clintfieldCommented:
So binding the first chart worked?
0
 
djshohitAuthor Commented:
Also, since the chart will be in one particular area of the application (area meaning the front end of the application), is it possible (or a good idea) to have overlapping each other?
0
 
djshohitAuthor Commented:
yea binding is fine. :).
0
 
clintfieldCommented:
Not sure what you mean by overlapping.
If we want to check for binding two charts,  I think we can try the code in the snippet.

           Chart1.DataSource = dt;
           Chart1.DataBind();
 
           Chart1.Series.Add("Totals");
           Chart1.Series["Totals"].ValueMemberX = Request.QueryString["xval1"].ToString();
           Chart1.Series["Totals"].ValueMembersY = Request.QueryString["yval1"].ToString();
 
if(Request.QueryString["xval2"] != null){
 
           Chart2.DataSource = dt;
           Chart2.DataBind();
           Chart2.Visible = true; 
 
           Chart2.Series.Add("Totals");
           Chart2.Series["Totals"].ValueMemberX = Request.QueryString["xval2"].ToString();
           Chart2.Series["Totals"].ValueMembersY = Request.QueryString["yval2"].ToString();
 
 
} else {
        Chart2.Visible = false; //now we wont see an empty chart on the page.
}

Open in new window

0
 
djshohitAuthor Commented:
Error: The name 'Chart2' does not exist in the current context.
that is what I mean. I think i need to have a chart2 tag in the .aspx page right?
 


0
 
clintfieldCommented:
That is correct.  Just drag one onto your form.  It should be named Chart2 by default.
0
 
djshohitAuthor Commented:
I think I didnt explain correctly. Let me explain better:
When we have 2 x and 2 y values, the chart should look something like this.
http://i34.tinypic.com/2nhj97k.jpg
When we have just one x and y value, the chart should look like a normal dundas chart, with one x and one y value.
Hope that makes things a little clear!
0
 
clintfieldCommented:
My company blocked that site you listed above.  Can you attach the jpg?
It sounds like you want one chart that charts two sets of data?  We have the first one working...now you want to add another dataset to the same chart?
0
 
djshohitAuthor Commented:
Exactly. I dont know if we need 2 datasets (I guess you would know better about it). Basically the 2 charts come from the same table but different columns. the YAxis1 and YAxis2 store the name of those columns.
appscreen.JPG
0
 
djshohitAuthor Commented:
So instead of having Chart2, can we add like another area in the chart to show 2 charts? I dont know how to add that code.
0
 
clintfieldCommented:
2 areas, 1 chart.  Both are bar graphs based on the same table with the same x(month) value, but different y(column) values?
0
 
djshohitAuthor Commented:
BINGO!
0
 
djshohitAuthor Commented:
no wait. One bar graph, one Line graph. The top graph is line graph, the botton graph is bar graph! Sorry.
0
 
clintfieldCommented:
Since we have the x and y values already, this sounds like we just need to figure out how to chart the two areas based on those values.  Instead of typing most of this out.  Try visiting this link and let me know if you need help integrating our vals with the technique.
 
http://www.dundas.com/Products/Chart/NET/Why/WhitePapers/ChartAreas.aspx 
0
 
djshohitAuthor Commented:
Yea I saw that. My problem here was that this chart changes according to values passed in it. So I dont know if this would work for it.
0
 
clintfieldCommented:
It would.  You just have to create your second chart area based on the x and y vals we have coming in from the querystring.  
0
 
djshohitAuthor Commented:
I guess I would need help to integrate that with my code. because anywhere in the code, it doesnt allow you to add X and Y values. Maybe I'm talking like a noob here. Could you help me with integrating this with my code?
0
 
clintfieldCommented:
You can set chartarea props using something like I have below.  Also, we need to attach each x,y series to a different chart area.  Does the code below give you any direction?
The first code block is about setting the props fo a chart area.
The second code block is for adding series to a chart.
The third code block is for attaching series to a chart area.

    // Set primary x-axis properties
    Chart1.ChartAreas["Default"].AxisY.MinorGrid.Interval = 0.25;
    Chart1.ChartAreas["Default"].AxisY.MajorGrid.Interval = 0.5;
    Chart1.ChartAreas["Default"].AxisY.LabelStyle.Interval = 0.5;
 
 
 
            // Add a series to the chart
            Series series = Chart1.Series.Add("Series1");
            series.ChartArea = "Default";
            series.ChartType = charts[Chart1.Series.Count-1];
            series.BorderWidth = 2;
 
 
 
    // Attach the first series to a chart area.
    Chart1.Series["Series1"].ChartArea = "Chart Area 1";
    
    // Attach the second series to a chart area.
    Chart1.Series["Series2"].ChartArea = "Chart Area 2";

Open in new window

0
 
djshohitAuthor Commented:
Error: the name chart doesnt exist in current context.
Wont this work instead of the line 11 you posted above?
Chart1.Series["Series11"].ChartArea = "ChartArea1
0
 
clintfieldCommented:
Sure.
0
 
clintfieldCommented:
I would assume your code looks similar to the snippet below.  
By the way, Im leaving for the weekend about 3:00 EST and I wont be back online until Wed next week.

Chart1.DataSource = dt;
Chart1.DataBind();
 
Series totals = Chart1.Series.Add("Totals");
totals.ChartArea = "ChartArea1";
 
 
totals.ValueMemberX = Request.QueryString["xval1"].ToString();
totals.ValueMembersY = Request.QueryString["xval1"].ToString();
 
if(Request.QueryString["xval2"] != ""){
 
Series totals2 = Chart1.Series.Add("Totals2");
totals2.ChartArea = "ChartArea2";
 
totals2.ValueMemberX = Request.QueryString["xval2"].ToString();
totals2.ValueMembersY = Request.QueryString["xval2"].ToString();
 
 
}

Open in new window

0
 
clintfieldCommented:
Whoops...second lines concerning Y vals should read:
totals.ValueMembersY = Request.QueryString["yval1"].ToString();

...
totals2.ValueMembersY = Request.QueryString["yval2"].ToString();
 

0
 
clintfieldCommented:
Have you gotten any of this to work?
0
 
djshohitAuthor Commented:
I think there is a problem in getting the graphs to come out right. It isnt filtering the data by country. So I tried a different method. Having 2 charts with an if else statement in the .aspx code. The problem is that I cant have a query where the name of the table is being input from a Query String.
 
I am attaching the code I have written. How can I get the data to be filtered by the country? Also shouldnt the C# code be in the click event of the dataset, instead of the page Load? i dont know how to capture the click event (if that is the case we'll use) of the dataset so might need help with that.

           <%if (Request.QueryString["yval2"] != "")
              {%>
                 
                <dcwc:Chart ID="Chart2" runat="server" BackColor="WhiteSmoke" 
                    BackGradientEndColor="White" BackGradientType="DiagonalLeft" 
                    BorderLineColor="26, 59, 105" BorderLineStyle="Solid" 
                    DataSourceID="YesX2Y2Value" Height="422px" Palette="Dundas" Width="764px">
                    <Legends>
                        <dcwc:Legend Alignment="Far" BackColor="White" BorderColor="26, 59, 105" 
                            Docking="Top" Enabled="False" LegendStyle="Column" Name="Default" 
                            ShadowOffset="2">
                        </dcwc:Legend>
                    </Legends>
                    <UI>
                        <Toolbar BorderColor="26, 59, 105">
                            <BorderSkin PageColor="Transparent" SkinStyle="Emboss" />
                        </Toolbar>
                    </UI>
                    <Titles>
                        <dcwc:Title Name="Title1">
                        </dcwc:Title>
                    </Titles>
                    <Series>
                        <dcwc:Series BorderColor="26, 59, 105" BorderWidth="2" ChartType="Line" 
                            Name="Series1" ShadowOffset="2"  ValueMemberX="Month">
                        </dcwc:Series>
                        <dcwc:Series ChartArea="Chart Area 1" Name="Series2" ValueMemberX="Month" 
                            XValueType="DateTime">
                        </dcwc:Series>
                    </Series>
                    <ChartAreas>
                        <dcwc:ChartArea BackColor="White" BorderColor="26, 59, 105" BorderStyle="Solid" 
                            Name="Default" ShadowOffset="2" AlignWithChartArea="Chart Area 1">
                            <AxisY>
                                <MajorGrid LineColor="Silver" />
                                <MinorGrid LineColor="Silver" />
                                <LabelStyle Format="N" />
                            </AxisY>
                            <AxisX>
                                <MajorGrid LineColor="Silver" />
                                <MinorGrid LineColor="Silver" />
                            </AxisX>
                            <AxisX2>
                                <MajorGrid LineColor="Silver" />
                                <MinorGrid LineColor="Silver" />
                            </AxisX2>
                            <AxisY2>
                                <MajorGrid LineColor="Silver" />
                                <MinorGrid LineColor="Silver" />
                            </AxisY2>
                        </dcwc:ChartArea>
                        <dcwc:ChartArea Name="Chart Area 1" BorderStyle="Solid" ShadowOffset="2">
                            <AxisY>
                                <LabelStyle Format="N" />
                            </AxisY>
                            <AxisX Margin="False">
                                <MajorTickMark Style="None" />
                                <LabelStyle Format="M" />
                            </AxisX>
                        </dcwc:ChartArea>
                    </ChartAreas>
                    <BorderSkin FrameBackColor="CornflowerBlue" 
                        FrameBackGradientEndColor="CornflowerBlue" PageColor="Control" 
                        SkinStyle="Emboss" />
                </dcwc:Chart><%}
              else
              {%>
              <dcwc:Chart ID="Chart1" runat="server" DataSourceID="Nox2y2Value" 
                    Palette="Pastel">
                    <Legends>
                        <dcwc:Legend Enabled="False" Name="Default">
                        </dcwc:Legend>
                    </Legends>
                    <Series>
                        <dcwc:Series BorderColor="64, 64, 64" BorderWidth="2" 
                            Name="Series1" ShadowOffset="1" ValueMemberX="Month">
                        </dcwc:Series>
                    </Series>
                    <ChartAreas>
                        <dcwc:ChartArea Name="Default">
                        </dcwc:ChartArea>
                    </ChartAreas>
                </dcwc:Chart>
                 <%} %>
                
            
            </td>
        </tr>
    </table>
    <asp:SqlDataSource ID="Nox2y2Value" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Global KPIConnectionString %>" 
        SelectCommand="SELECT @Col1, @Col2 
FROM @Table1 
WHERE Country=@Country">
        <SelectParameters>
            <asp:QueryStringParameter Name="Col1" QueryStringField="xval1" 
                DefaultValue="Month" />
            <asp:QueryStringParameter Name="Col2" QueryStringField="yval1" />
            <asp:QueryStringParameter Name="Table1" QueryStringField="reportName" 
                DefaultValue="" />
            <asp:ControlParameter ControlID="CountryListDropDown" Name="Country" 
                PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="YesX2Y2Value" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Global KPIConnectionString %>" 
        
        SelectCommand="SELECT @X1, @Y1, @Y2 FROM @TableName WHERE Country = @Country">
        <SelectParameters>
            <asp:QueryStringParameter Name="X1" QueryStringField="xval1" 
                DefaultValue="Month" />
            <asp:QueryStringParameter DefaultValue="" Name="Y1" QueryStringField="yval1" />
            <asp:QueryStringParameter DefaultValue="" Name="Y2" QueryStringField="yval2" />
            <asp:QueryStringParameter Name="TableName" QueryStringField="reportName" />
            <asp:ControlParameter ControlID="CountryListDropDown" Name="Country" 
                PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:SqlDataSource>
 
------------------
 
 protected void Page_Load(object sender, EventArgs e)
    {
        
 
       
        if (Request.QueryString["yval2"] != "")
        {
            
            Chart2.Series["Series1"].ValueMemberX = Request.QueryString["xval1"];
            Chart2.Series["Series1"].ValueMembersY = Request.QueryString["yval1"];
          
            Chart2.Series["Series2"].ValueMemberX = Request.QueryString["xval2"];
            Chart2.Series["Series2"].ValueMembersY = Request.QueryString["yval2"];
        }
 
        else
        {
            Chart2.Series["Series1"].ValueMemberX = Request.QueryString["xval1"];
            Chart2.Series["Series1"].ValueMemberX = Request.QueryString["yval1"];
        }

Open in new window

0
 
clintfieldCommented:
I would do it in the page load.  There isnt a need to do a click event.  When you click on the link it essentially reloads the page, then you test for the querystring vars.  Depending on what vars are present, you display the graph(s). (See the snippet)
Does this method not work?
 

protected void Page_Load(object sender, EventArgs e){
if(Request.QueryString["xval1"] != ""){
 
     DataTable dt = new DataTable();
     dt = somemethodtogetdata
 
     Chart1.DataSource = dt; //dt is the data you need to chart
     Chart1.DataBind();
 
     Series totals = Chart1.Series.Add("Totals");
     totals.ChartArea = "ChartArea1";
 
 
     totals.ValueMemberX = Request.QueryString["xval1"].ToString();
     totals.ValueMembersY = Request.QueryString["yval1"].ToString();
 
     if(Request.QueryString["xval2"] != ""){
 
          Series totals2 = Chart1.Series.Add("Totals2");
          totals2.ChartArea = "ChartArea2";
 
          totals2.ValueMemberX = Request.QueryString["xval2"].ToString();
          totals2.ValueMembersY = Request.QueryString["yval2"].ToString();
     }
} 
}

Open in new window

0
 
djshohitAuthor Commented:
But it isnt gonna take values and filter by country. Thats why the first code worked, but it didnt filter any results which resulted in a wierd graph. There needs to be a where clause somewhere, right?
0
 
clintfieldCommented:
A where clause would filter.  Thats where your previous dropdown selections come in handy for the datacall that populates your grid.
dt = methodToSelectWithWhereClause
Make sense?
0
 
djshohitAuthor Commented:
Ok I guess I might need help with that method too. Sorry to bug you so much. I have attached the code below. I tried using the where clause and it gave me errors. Could you help me with that? I think we're almost done here.
 
 

 protected void Page_Load(object sender, EventArgs e)
    {
        
 
       if(Request.QueryString["xval1"] != ""){
 
     DataTable dt = CallDataTable();
     
 
     Chart1.DataSource = dt; //dt is the data you need to chart
     Chart1.DataBind();
 
     Series totals = Chart1.Series.Add("Totals");
     totals.ChartArea = "ChartArea1";
 
 
     totals.ValueMemberX = Request.QueryString["xval1"].ToString();
     totals.ValueMembersY = Request.QueryString["yval1"].ToString();
 
     if(Request.QueryString["xval2"] != ""){
 
          Series totals2 = Chart1.Series.Add("Totals2");
          totals2.ChartArea = "ChartArea2";
 
          totals2.ValueMemberX = Request.QueryString["xval2"].ToString();
          totals2.ValueMembersY = Request.QueryString["yval2"].ToString();
     }
}}
        public DataTable CallDataTable()
        {
            DataTable dt = new DataTable();
            SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["Global KPIConnectionString"]);
            connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Global KPIConnectionString"].ConnectionString;
            connection.Open();
 
            SqlCommand sqlCmd = new SqlCommand("SELECT * FROM " + Request.QueryString["reportName"].ToString(), connection);
            SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
            sqlDa.Fill(dt);
 
        }

Open in new window

0
 
djshohitAuthor Commented:
The error I get with the code above is as follows:
 
Error 1 '_Default.CallDataTable()': not all code paths return a value
0
 
djshohitAuthor Commented:
Ok I didnt have a return value. Stupid error. But the following error is something I get a lot when I was trying something. Its probably something basic too, but I havent been able to figure out whats wrong here!
query.JPG
0
 
djshohitAuthor Commented:
Ok I got to fix that. I just need to do the where thing. I think thats the only thing I need help with so far. I'm attaching the code written thus far!
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["reportName"] != null)
        {
 
            if (Request.QueryString["xval1"] != "")
            {
 
                DataTable dt = CallDataTable();
 
 
                Chart1.DataSource = dt; //dt is the data you need to chart
                Chart1.DataBind();
 
                Series totals = Chart1.Series.Add("Totals");
                totals.ChartArea = "ChartArea1";
 
 
                totals.ValueMemberX = Request.QueryString["xval1"].ToString();
                totals.ValueMembersY = Request.QueryString["yval1"].ToString();
 
                if (Request.QueryString["xval2"] != "")
                {
 
                    Series totals2 = Chart1.Series.Add("Totals2");
                    totals2.ChartArea = "ChartArea2";
 
                    totals2.ValueMemberX = Request.QueryString["xval2"].ToString();
                    totals2.ValueMembersY = Request.QueryString["yval2"].ToString();
                }
 
            }
        }
    }
 
        public DataTable CallDataTable()
        {
            
                DataTable dt = new DataTable();
                SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["Global KPIConnectionString"]);
                connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Global KPIConnectionString"].ConnectionString;
                connection.Open();
                
                SqlCommand sqlCmd = new SqlCommand("SELECT * FROM " + Request.QueryString["reportName"].ToString(), connection);
 
                SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
                sqlDa.Fill(dt);
            
                return dt;
            
        }

Open in new window

0
 
clintfieldCommented:
These emails are now getting blocked by my spam filter for some reason....
Anyway, it looks like you just about got it!  I think the where clause will come from the one dropdown you have for country.  I slightly modified the code above.  CountryDropDownList is what I called your dropdown for listing countries.

        public DataTable CallDataTable()
        {
            
                DataTable dt = new DataTable();
                SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["Global KPIConnectionString"]);
                connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Global KPIConnectionString"].ConnectionString;
                connection.Open();
                
                SqlCommand sqlCmd = new SqlCommand("SELECT * FROM " + Request.QueryString["reportName"].ToString() + " WHERE Country = '" + CountryDropDownList.SelectedValue + "'", connection);
 
                SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
                sqlDa.Fill(dt);
            
                return dt;
            
        }

Open in new window

0
 
djshohitAuthor Commented:
Ok I think I have almost got it, except one thing. It might be out of the scope of this question, but if you can answer it, it would be great! My deadline is today and I have just about got it!
The two drop downs, with country and city? When I click on the datalist link, their state changes to default types! Is there a way to keep their state intact?
Also is there a way so that the drop downs dont have any values selected (instead of the first value in the drop downs being selected)? I would prefer if the user explicitly selects the value. Sometimes the "Area" drop down only has one value, and it gets selected by default.
Thanks
0
 
djshohitAuthor Commented:
Cause whenever one value in the datalist gets selected, the drop down change to their initial values, which sucks because when a user selects some other reportname in the datalist, it is actually showing the charts for a different set of data.
I dont have any default value set for the DropDowns.
0
 
clintfieldCommented:
You dont have a dropdown option like "Choose One" that is automatically selected when the page is first shown?  Is this what you want?
0
 
djshohitAuthor Commented:
Yea. Basically when the dropdown is loaded, nothing should be selected. And once the value is being selected, the state of that dropdown remains intact, even after the DataList Item is clicked (which currently it changes to the first value available in the drop down).
Also, the code that you gave me gives an error. I thought I'll use the querystring to use the country from the table itself (which should work), but I do think selecting the dropdown value is better.
Here's the error:

Error	83	'System.Web.UI.WebControls.SqlDataSource' does not contain a definition for 'SelectedValue' and no extension method 'SelectedValue' accepting a first argument of type 'System.Web.UI.WebControls.SqlDataSource' could be found (are you missing a using directive or an assembly reference?)	

Open in new window

0
 
djshohitAuthor Commented:
Thank you for your prompt responses!!!! :)
0
 
djshohitAuthor Commented:
Dont worry about the error! Its the other problem that needs to be fixed. Otherwise we seem to be all set for now!
0
 
clintfieldCommented:
First, be sure you are loading the dropdownlist in the pageload using:
if(!IsPostBack){
      //load dropdowns
}
 
This way you can be sure that the selected values persist between pageloads.
To initially display "Choose One" in the dropdowns look at the code snippet.


ddlCountryList.DataTextField = "Name";
ddlCountryList.DataValueField = "ID";
ddlCountryList.DataSource = somedatatable;
ddlCountryList.DataBind();
 
ddlBuildings.Items.Add(new ListItem("Choose One", "Choose One"));

Open in new window

0
 
djshohitAuthor Commented:
This is my final piece of code. Another error I get when I click around is as follows, which I have absolutely no clue how to handle it!
 "The chart series [MonsterIBSSeries1] is missing and cannot be deserialized. You can use Chart.CallbackStateContent="All" to preserve all chart content inlcuding series."
This happens when I try to change the country/Area AFTER I view the charts.
2 more things left and we are done! I am indebt to you for all your help!  

 protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["reportName"] != null)
        {
 
            if (Request.QueryString["xval2"] != "")
            {
 
                Chart2.Visible = false;
                DataTable dt = CallDataTable(Request.QueryString["xval1"].ToString(), Request.QueryString["yval1"].ToString(), Request.QueryString["yval2"].ToString(), CountryDropDownControl.SelectedValue.ToString());
 
 
                Chart1.DataSource = dt; //dt is the data you need to chart
                Chart1.DataBind();
 
                //   Chart1.Series["Series1"].ChartArea = "Default";
                Series totals = Chart1.Series.Add("MonsterIBSSeries1");
                totals.ChartArea = "Default";
 
 
                totals.ValueMemberX = Request.QueryString["xval1"].ToString();
                totals.ValueMembersY = Request.QueryString["yval1"].ToString();
 
                Series totals2 = Chart1.Series.Add("MonsterIBSSeries2");
                totals2.ChartArea = "ChartArea1";
 
 
                //Preserve state of callback
                // Chart1.CallbackStateContent = CallbackStateContent.All;
 
                totals2.ValueMemberX = Request.QueryString["xval2"].ToString();
                totals2.ValueMembersY = Request.QueryString["yval2"].ToString();
                Chart1.ChartAreas["Default"].CursorX.UserEnabled = true;
                Chart1.ChartAreas["ChartArea1"].CursorX.UserEnabled = true;
 
                Chart1.ChartAreas["Default"].AlignWithChartArea = "ChartArea1";
                Chart1.ChartAreas["Default"].AlignOrientation = AreaAlignOrientation.Vertical;
                Chart1.ChartAreas["Default"].AlignType = AreaAlignType.All;
            }
            else
            {
                Chart1.Visible = false;
 
 
 
                DataTable dt = CallDataTable1(Request.QueryString["xval1"].ToString(), Request.QueryString["yval1"].ToString(), CountryDropDownControl.SelectedValue.ToString());
 
                Chart1.DataSource = dt; //dt is the data you need to chart
                Chart1.DataBind();
 
 
                Series totals = Chart2.Series.Add("MonsterIBSSeries1");
                totals.ChartArea = "Default";
 
 
                totals.ValueMemberX = Request.QueryString["xval1"].ToString();
                totals.ValueMembersY = Request.QueryString["yval1"].ToString();
 
                Chart2.DataBind();
                //  totals.ValueMembersY = Request.QueryString["yval1"].ToString();
                Chart2.ChartAreas["Default"].CursorX.UserEnabled = true;
            }
 
        
        }
        else
        {
            Chart1.Visible = false;
            Chart2.Visible = false;
        }
    }
 
   
    public DataTable CallDataTable(string xval1, string yval1, string yval2, string country)
    {
 
        DataTable dt = new DataTable();
        SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["Global KPIConnectionString"]);
        connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Global KPIConnectionString"].ConnectionString;
        connection.Open();
 
        SqlCommand sqlCmd = new SqlCommand("SELECT [" + xval1 + "], [" + yval1 + "], [" + yval2 + "] FROM " + Request.QueryString["reportName"].ToString() + " WHERE Country = '" + 
           CountryDropDownControl.SelectedValue + "'", connection);
 
        SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
        sqlDa.Fill(dt);
 
        return dt;
 
    }
 
    public DataTable CallDataTable1(string xval1, string yval1, string country)
    {
        DataTable dt = new DataTable();
        SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["Global KPIConnectionString"]);
        connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Global KPIConnectionString"].ConnectionString;
        connection.Open();
        // String dropdownvalue = CountryListDropDown.SelectedValue.ToString();
        // String dropdownval = Delete.Text;
        SqlCommand sqlCmd = new SqlCommand("SELECT [" + xval1 + "], [" + yval1 + "] FROM [" + Request.QueryString["reportName"].ToString() + "] WHERE Country= '" + CountryDropDownControl.SelectedValue + "'", connection);
        // "WHERE Country = " + dropdownvalue, connection);
        SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
        sqlDa.Fill(dt);
 
        return dt;
    }
}

Open in new window

0
 
clintfieldCommented:
So basically everything works unless they try to choose another set of options after viewing the charts.  Then you get this error?
I would put a break point on the pageload and see what values are getting passed in.  Step through the code until it breaks.  What line breaks?  Im assuming its Chart1.DataBind();
 
 
0
 
djshohitAuthor Commented:
Yes. thats what breaks!!! Why do you think thats the case?
0
 
djshohitAuthor Commented:
Also, Could you help me with the ISPostBack thing? There are a bunch of codes available online to help me out on that. Unfortunately none of them work!
0
 
djshohitAuthor Commented:
The break error usually gets to something like this:
 
Cannot add series. A series with the name "MonsterIBSSeries1" already exists.  
This occurs on the line :

Series totals = Chart1.Series.Add("MonsterIBSSeries1")
 
:(
0
 
djshohitAuthor Commented:
Here's the postback error I get. Its probably a syntax thing, except I have no idea to solve it!
postbackerror.JPG
0
 
clintfieldCommented:
Ive never dealt with the chart error before.  Try adding this Chart1.Series.Clear() right after:
        if (Request.QueryString["reportName"] != null)
        {
...
Do the same for Chart2.Series.Clear().  Im not sure if this will work and its a little hacky, but clearing out the series may help.
As far as postback error, why do you have this line - CountryDropDownControl.DataSourceID?  Cant you take that out?  Ive never used that before.  I also notice that you are getting the selectedvalue right after you bind....that is gonna give you the same value for that string every time.  Close your if(!ispostback) block after you DataBind();
0
 
djshohitAuthor Commented:
I dont think I understand the following:
ountryList.DataTextField = "Name";
ddlCountryList.DataValueField = "ID";

I dont think I have an ID column in my table. Is that what this is mapping to?
0
 
djshohitAuthor Commented:
I was trying to make it work, hence I was trying to do a few things.

CountryDropDownControl.DataTextField= "ReportName";
CountryDropDownControl.DataSource = CountryDropDownList;
CountryDropDownControl.DataBind();
CountryDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
I get the error :
Both DataSource and DataSourceID are defined on 'CountryDropDownControl'.  Remove one definition."
 
0
 
clintfieldCommented:
CountryList.DataTextField = "Name"; //this is the text you see in the dropdown
ddlCountryList.DataValueField = "ID"; //this is the option value.
You can make both of these Name if you want.  Whatever you feel comfortable with.  
Make sure you have defined this:
CountryDropDownControl.DataTextField= "ReportName";
CountryDropDownControl.DataValueField= "ReportName";  
 Then you can do the rest.
CountryDropDownControl.DataSource = CountryDropDownList;
CountryDropDownControl.DataBind();
CountryDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
 
That should work....
0
 
djshohitAuthor Commented:
I did exactly as you mentioned earlier. Apparently it puts "Choose One" at the bottom of the list. Can it be at the top of the list so it gets selected?
  if (!IsPostBack)
        {
            CountryDropDownControl.DataTextField= "ReportCountry";
            CountryDropDownControl.DataSource = CountryDropDownList;
            CountryDropDownControl.DataBind();
            CountryDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
 
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataSource = AreaDropDownList;
            AreaDropDownControl.DataBind();
            AreaDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
        }

Open in new window

0
 
djshohitAuthor Commented:
Choose One is at the bottom. Unfortunately the functionality doesnt remain! As soon as I click the datalist, the value goes back to Belgium for Country and National for Area! :(

 if (!IsPostBack)
        {
            CountryDropDownControl.DataTextField= "ReportCountry";
            CountryDropDownControl.DataValueField = "ReportCountry";  
            CountryDropDownControl.DataSource = CountryDropDownList;
            CountryDropDownControl.DataBind();
          CountryDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
 
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataValueField = "Area";  
            AreaDropDownControl.DataSource = AreaDropDownList;
            AreaDropDownControl.DataBind();
            AreaDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
        }

Open in new window

0
 
clintfieldCommented:
Ah...I think I remember why.  Your datalist links dont postback...they call the page again and pass the querystring.  Try the code snippet.
This makes sure that its not a postback and its also not the datalist links calling the page with a querystring.  

 if (!IsPostBack && Request.QueryString["xval1"] == null)
        {
            CountryDropDownControl.DataTextField= "ReportCountry";
            CountryDropDownControl.DataValueField = "ReportCountry";  
            CountryDropDownControl.DataSource = CountryDropDownList;
            CountryDropDownControl.DataBind();
          CountryDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
 
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataValueField = "Area";  
            AreaDropDownControl.DataSource = AreaDropDownList;
            AreaDropDownControl.DataBind();
            AreaDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
        }

Open in new window

0
 
djshohitAuthor Commented:
I did the following and it has some errors but it should work eventually. The problem is that now the Area Drop Down Doesnt populate. I am assuming its taking the "Choose One" Value to populate the data and its not helping it!'
CountryDropDownControl.DataTextField= "ReportCountry";
            CountryDropDownControl.DataValueField = "ReportCountry";  
            CountryDropDownControl.DataSource = CountryDropDownList;
            CountryDropDownControl.DataBind();
            CountryDropDownControl.Items.Insert(0, new ListItem("Choose One"));
          // CountryDropDownControl.Items.Add(new ListItem("Choose One"));
 
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataValueField = "Area";  
            AreaDropDownControl.DataSource = AreaDropDownList;
            AreaDropDownControl.DataBind();
            AreaDropDownControl.Items.Insert(0, new ListItem("Choose One"));
         //  AreaDropDownControl.Items.Add(new ListItem("Choose One"));
            

Open in new window

0
 
djshohitAuthor Commented:
Yup. Now I am stuck and a little terrified :-P
The Area Control Doesnt populate anymore! It just says "Choose One". I didnt change anything, just the code (which happens to be pretty similar to what you mentioned). Aaah...any ideas?

   if (!IsPostBack && Request.QueryString["xval1"] == null)
 
        {
            CountryDropDownControl.DataTextField= "ReportCountry";
            CountryDropDownControl.DataValueField = "ReportCountry";  
            CountryDropDownControl.DataSource = CountryDropDownList;
            CountryDropDownControl.DataBind();
            CountryDropDownControl.Items.Insert(0, new ListItem("Choose One", "Choose One"));
        
 
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataValueField = "Area";  
            AreaDropDownControl.DataSource = AreaDropDownList;
            AreaDropDownControl.DataBind();
            AreaDropDownControl.Items.Insert(0, new ListItem("Choose One", "Choose One"));
         
        }

Open in new window

0
 
clintfieldCommented:
Items.Insert and Items.Add are different.  I think you are wiping the values out with Add.  
Use the add and try this to select Choose One.
 


CountryDropDownControl.SelectedIndex = CountryDropDownControl.Items.IndexOf(CountryDropDownControl.Items.FindByValue("Choose One"));

Open in new window

0
 
djshohitAuthor Commented:
Yea I did as you said. The Area Control doesnt populate anymore. I tried to bind it directly, and then it populates - just to make sure that the Connection is on and the database is fine.
!!BREATHER!!. ..So now what, pretty annoying problem huh!?! :)
0
 
djshohitAuthor Commented:
Here's the code I tried. FYI I did try both Insert and Add. Same effect really!
     CountryDropDownControl.DataTextField= "ReportCountry";
            CountryDropDownControl.DataValueField = "ReportCountry";  
            CountryDropDownControl.DataSource = CountryDropDownList;
            CountryDropDownControl.DataBind();
            CountryDropDownControl.Items.Add(new ListItem("Choose One"));
          //  CountryDropDownControl.Items.Insert(0, new ListItem("Choose One"));
            CountryDropDownControl.SelectedIndex = CountryDropDownControl.Items.IndexOf(CountryDropDownControl.Items.FindByValue("Choose One"));
        
 
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataValueField = "Area";  
            AreaDropDownControl.DataSource = AreaDropDownList;
            AreaDropDownControl.DataBind();
            AreaDropDownControl.Items.Add(new ListItem("Choose One"));
           // AreaDropDownControl.Items.Insert(0, new ListItem("Choose One"));
           AreaDropDownControl.SelectedIndex = AreaDropDownControl.Items.IndexOf(AreaDropDownControl.Items.FindByValue("Choose One")); 

Open in new window

0
 
clintfieldCommented:
So, what isnt working now?  If you do this, it should work fine.
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataValueField = "Area";  
            AreaDropDownControl.DataSource = AreaDropDownList;
            AreaDropDownControl.DataBind();
            AreaDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
            AreaDropDownControl.SelectedIndex = AreaDropDownControl.Items.IndexOf(AreaDropDownControl.Items.FindByValue("Choose One"));
 
 
0
 
djshohitAuthor Commented:
Yea I tried that...didnt work :(
DropDown.bmp
0
 
clintfieldCommented:
Im not sure what the deal is here.  The above code should work without any issues.  Copy and paste your whole pageload content.  
0
 
djshohitAuthor Commented:
Here you Go!
public partial class Economy : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
     {
        
 
   
 
         if (!IsPostBack && Request.QueryString["xval1"] == null)
 
        {
            CountryDropDownControl.DataTextField= "ReportCountry";
            CountryDropDownControl.DataValueField = "ReportCountry";  
            CountryDropDownControl.DataSource = CountryDropDownList;
            CountryDropDownControl.DataBind();
          
          
            CountryDropDownControl.SelectedIndex = CountryDropDownControl.Items.IndexOf(CountryDropDownControl.Items.FindByValue("Choose One"));
 
 
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataValueField = "Area";
            AreaDropDownControl.DataSource = AreaDropDownList;
            AreaDropDownControl.DataBind();
            AreaDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
            AreaDropDownControl.SelectedIndex = AreaDropDownControl.Items.IndexOf(AreaDropDownControl.Items.FindByValue("Choose One"));
 
 
            
        }
 
 
         
        
         
         
        if (Request.QueryString["reportName"] != null)
        {
 
            if (Request.QueryString["xval2"] != "")
            {
 
               // Chart1.CallbackStateContent= CallbackStateContent.All;
                Chart2.Visible = false;
                DataTable dt = CallDataTable(Request.QueryString["xval1"].ToString(), Request.QueryString["yval1"].ToString(), Request.QueryString["yval2"].ToString(), CountryDropDownControl.SelectedValue.ToString());
 
 
                Chart1.DataSource = dt; //dt is the data you need to chart
                Chart1.DataBind();
 
                //   Chart1.Series["Series1"].ChartArea = "Default";
                Series totals = Chart1.Series.Add("MonsterIBSSeries1");
                totals.ChartArea = "Default";
 
 
                totals.ValueMemberX = Request.QueryString["xval1"].ToString();
                totals.ValueMembersY = Request.QueryString["yval1"].ToString();
                totals.Type = SeriesChartType.Line;
                totals.Color = Color.Red;
                totals.BorderWidth = 3;
                
 
                Series totals2 = Chart1.Series.Add("MonsterIBSSeries2");
                totals2.ChartArea = "ChartArea1";
 
 
                //Preserve state of callback
                // Chart1.CallbackStateContent = CallbackStateContent.All;
 
                totals2.ValueMemberX = Request.QueryString["xval2"].ToString();
                totals2.ValueMembersY = Request.QueryString["yval2"].ToString();
              //  Chart1.ChartAreas["Default"].CursorX.UserEnabled = true;
               //Chart1.ChartAreas["ChartArea1"].CursorX.UserEnabled = true;
 
                Chart1.ChartAreas["Default"].AlignWithChartArea = "ChartArea1";
                Chart1.ChartAreas["Default"].AlignOrientation = AreaAlignOrientation.Vertical;
                Chart1.ChartAreas["Default"].AlignType = AreaAlignType.All;
            }
            else
            {
                Chart1.Visible = false;
 
 
 
                DataTable dt = CallDataTable1(Request.QueryString["xval1"].ToString(), Request.QueryString["yval1"].ToString(), CountryDropDownControl.SelectedValue.ToString());
 
                Chart2.DataSource = dt; //dt is the data you need to chart
                Chart2.DataBind();
 
 
                Series totals = Chart2.Series.Add("MonsterIBSSeries1");
                totals.ChartArea = "Default";
                
 
 
                totals.ValueMemberX = Request.QueryString["xval1"].ToString();
                totals.ValueMembersY = Request.QueryString["yval1"].ToString();
 
                
                totals.ValueMembersY = Request.QueryString["yval1"].ToString();
             }
 
        
        }
        else
        {
            Chart1.Visible = false;
            Chart2.Visible = false;
        }
    }
 
   
    public DataTable CallDataTable(string xval1, string yval1, string yval2, string country)
    {
 
        DataTable dt = new DataTable();
        SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["Global KPIConnectionString"]);
        connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Global KPIConnectionString"].ConnectionString;
        connection.Open();
 
        SqlCommand sqlCmd = new SqlCommand("SELECT [" + xval1 + "], [" + yval1 + "], [" + yval2 + "] FROM " + Request.QueryString["reportName"].ToString() + " WHERE Country = '" + 
           CountryDropDownControl.SelectedValue + "'", connection);
 
        SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
        sqlDa.Fill(dt);
 
        return dt;
 
    }
 
    public DataTable CallDataTable1(string xval1, string yval1, string country)
    {
        DataTable dt = new DataTable();
        SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["Global KPIConnectionString"]);
        connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Global KPIConnectionString"].ConnectionString;
        connection.Open();
        SqlCommand sqlCmd = new SqlCommand("SELECT [" + xval1 + "], [" + yval1 + "] FROM [" + Request.QueryString["reportName"].ToString() + "] WHERE Country= '" + CountryDropDownControl.SelectedValue + "'", connection);
        SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
        sqlDa.Fill(dt);
 
        return dt;
    }
  
}

Open in new window

0
 
djshohitAuthor Commented:
This is the Postback code
   if (!IsPostBack && Request.QueryString["xval1"] == null)
 
        {
            CountryDropDownControl.DataTextField= "ReportCountry";
            CountryDropDownControl.DataValueField = "ReportCountry";  
            CountryDropDownControl.DataSource = CountryDropDownList;
            CountryDropDownControl.DataBind();
            AreaDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
                      CountryDropDownControl.SelectedIndex = CountryDropDownControl.Items.IndexOf(CountryDropDownControl.Items.FindByValue("Choose One"));
 
 
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataValueField = "Area";
            AreaDropDownControl.DataSource = AreaDropDownList;
            AreaDropDownControl.DataBind();
            AreaDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
            AreaDropDownControl.SelectedIndex = AreaDropDownControl.Items.IndexOf(AreaDropDownControl.Items.FindByValue("Choose One"));
 
 
            
        }

Open in new window

0
 
clintfieldCommented:
Does the control come up empty after the postback?  Its interesting how the countrydropdowncontrol works using the same code.  
Everything looks good.  Step through the code that populates the areadropdowncontrol and be sure that it returns data each time and the text and value fields are correctly set.
 
0
 
djshohitAuthor Commented:
Sorry I meant this one!.
  if (!IsPostBack && Request.QueryString["xval1"] == null)
 
        {
            CountryDropDownControl.DataTextField= "ReportCountry";
            CountryDropDownControl.DataValueField = "ReportCountry";  
            CountryDropDownControl.DataSource = CountryDropDownList;
            CountryDropDownControl.DataBind();
            CountryDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
          
            CountryDropDownControl.SelectedIndex = CountryDropDownControl.Items.IndexOf(CountryDropDownControl.Items.FindByValue("Choose One"));
 
 
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataValueField = "Area";
            AreaDropDownControl.DataSource = AreaDropDownList;
            AreaDropDownControl.DataBind();
            AreaDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
            AreaDropDownControl.SelectedIndex = AreaDropDownControl.Items.IndexOf(AreaDropDownControl.Items.FindByValue("Choose One"));
 
 
            
        }

Open in new window

0
 
clintfieldCommented:
They look the same to me.  But Im assuming the postback code here is in the page_load event.
Step through the code and look for something fishy.  Your code looks good to me.  Im heading out for the day.  Good luck.
0
 
djshohitAuthor Commented:
Yes it is in the page_load event!
0
 
clintfieldCommented:
Did you find anything after stepping through the code?  I dont see anything wrong with your code and Ive tested the method we are using and it works fine.  You should be able to bind, add an item, then select that index.  Also make sure you have Areas for the Country you choose.
Hmmm...one more thought.  If you select a country, the Area dropdown should change.  So the steps are like this:
1.  Load page with countries, preselecting "Choose One".
2.  Select a country.
3.  Area dropdown uses the country selection to fill the areas.
If this is correct, then you actually need to do the following.
1.  Double click (in design mode) on your Country dropdown.
2.  Take your AreaDropDownControl binding and put it in the method that is created from double clicking the Country dropdown.
3.  Be sure your AreaDropDownControl binding uses the country selected to get the correct data(areas.)
See the snippet for an example of this.
I think our problem is that since the areadropdownlist only populates during the initial loading of the page, and since it uses the preselected option of Choose One for country, it obviously has no areas for the country Choose One.
Make sense?  Use the snippet example to populate the area control every time a new country is selected.


private void CountryDropDownControl_SelectedIndexChanged(object sender, System.EventArgs e)
{
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataValueField = "Area";
            AreaDropDownControl.DataSource = AreaDropDownList;
            AreaDropDownControl.DataBind();
            AreaDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
            AreaDropDownControl.SelectedIndex = AreaDropDownControl.Items.IndexOf(AreaDropDownControl.Items.FindByValue("Choose One"));
 
		
}

Open in new window

0
 
djshohitAuthor Commented:
Almost there! Yea I did try that yesterday (and I'm glad you thought of that too!!). I did put the code you suggested in the  CountryDropDownControl_SelectedIndexChanged method.
It works fine until I click on an item in the DataList! Once I click on an item, dropdown values vanish showing two empty dropdowns! My guess this has something to do with the "&& Request.QueryString["xval1"] == null" section of the if (!IsPostback statement!
0
 
clintfieldCommented:
Yep, we talked about this in a previous comment.  Its not really a postback since the querystring changes.  So we just need to be sure that the country dropdown populates everytime the querystring changes.  
It appears that it works, its just the dropdowns are the issue now, right?
We need to do the following:
1.  Be sure to populate the country dropdown when the page is loaded (pre-selecting the value Choose One value on the initial page loading, and pre-selecting the selected country every other time.  (See #1snippet for this)
2.  Add an html hidden value on the page that stores the selected country dropdown.  Every time the country dropdown changes, this hidden saves the value. (See else statement in snippet #1 and selected change event in #2.)  I add an html hidden value on the page, the right click and run as server control.  Name it "hdnCountry".
If the area dropdown loses its value anywhere in the process, you may want to also do a selected index change event on this one that sets another hidden value as well.  But Im not sure you will need this.  Test what we have here and see if it works.
There is probably a cleaner way to do this, but it should work.  You can play around with the details and flow.  You may want to put the dropdown population stuff in their own method and then call it, etc.
By the way....I think we solved the original issue, dont you think?

#1:
//page load
  if (!IsPostBack && Request.QueryString["xval1"] == null)
 
        {
            CountryDropDownControl.DataTextField= "ReportCountry";
            CountryDropDownControl.DataValueField = "ReportCountry";  
            CountryDropDownControl.DataSource = CountryDropDownList;
            CountryDropDownControl.DataBind();
            CountryDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
          
            CountryDropDownControl.SelectedIndex = CountryDropDownControl.Items.IndexOf(CountryDropDownControl.Items.FindByValue("Choose One"));            
        }
else if(!IsPostBack && Request.QueryString["xval1"] != null){
            //this populates the country control and preselects the country they selected
 
            CountryDropDownControl.DataTextField= "ReportCountry";
            CountryDropDownControl.DataValueField = "ReportCountry";  
            CountryDropDownControl.DataSource = CountryDropDownList;
            CountryDropDownControl.DataBind();
 
CountryDropDownControl.SelectedIndex = CountryDropDownControl.Items.IndexOf(CountryDropDownControl.Items.FindByValue(Request.Form[hdnCountry.Value]));
 
           //now populate the area dropdown based on the country again.
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataValueField = "Area";
            AreaDropDownControl.DataSource = AreaDropDownList; //be sure that this method is getting the latest country selected (if not, use the hidden value on your page to query the db.)
            AreaDropDownControl.DataBind();
            AreaDropDownControl.SelectedIndex = AreaDropDownControl.Items.IndexOf(AreaDropDownControl.Items.FindByValue("Choose One"));
}
 
 
private void CountryDropDownControl_SelectedIndexChanged(object sender, System.EventArgs e)
{
     hdnCountry.Value = CountryDropDownControl.SelectedValue;
 
            AreaDropDownControl.DataTextField = "Area";
            AreaDropDownControl.DataValueField = "Area";
            AreaDropDownControl.DataSource = AreaDropDownList;
            AreaDropDownControl.DataBind();
            AreaDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
            AreaDropDownControl.SelectedIndex = AreaDropDownControl.Items.IndexOf(AreaDropDownControl.Items.FindByValue("Choose One"));
 
		
}

Open in new window

0
 
djshohitAuthor Commented:
yes we are done with this question. But pls need an urgent answer to this since we are so close to finishing this. If I post another question, it might hard to get your attention. And believe me, I dont have any problems posting another question. Its just that this thing is due "yesterday" sorta thing and we are just about done here. Plus, you know this inside out :)
PLS PLS we are so close.... :)
I did exactly as you said. This is what happens:
1) I click on Country Drop Down (at this time the Area drop down is empty), and select the country.
2) The AreaDropDown populates, and then I select the Area
3) The DataList gets populated. I select the Report and the chart shows up! The values of the drop downs are set back to Belgium and National. Choose One options are gone. The labels that I had setup to show me the Country and Area Selected are empty
To clarify, the postback statements are in PageLoad. I debugged through code it seemed that the hdnCountry parameter isnt being set.

<asp:HiddenField ID="hdnCountry" runat="server" />

Open in new window

0
 
djshohitAuthor Commented:
I guess instead of having a hidden value, I could have used the value set to the label as well. The problem is that, the state gets lost! Wow I had no idea setting the state could be this much of a pain!
0
 
clintfieldCommented:
It looks like you have an asp hidden field.  I prefer to use an html one.  It should look like this:   <INPUT id="hdnCountry" type="hidden" name="hdnCountry" runat="server">
Maybe the best way to set the hidden values is to do this in the page load:

CountryDropDownList.Attributes.Add("onchange","setVal(this.value)");
 
Then you need a javascript function called setVal(val).  Put this in your head tags.
<script type="text/javascript">
  function setVal(val)
  {
     
     aspnetForm.hdnCountry.value=val;
     
   
  }
</script>
 Ive tested this and it works.  You can do the same for area if you need to.  You can even have your labels use the hidden vals.
Another option instead of hidden vals is using session vars.  But lets try this first.  
0
 
djshohitAuthor Commented:
Linq Error?
Error	1	'System.Xml.Linq.Extensions.Attributes(System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>, System.Xml.Linq.XName)' is a 'method', which is not valid in the given context
 
 
----------------------
 
protected void Page_Load(object sender, EventArgs e)
     {
         CountryDropDownList.Attributes.Add("onchange", "setVal(this.value)"); //THIS IS THE CODE YOU HAD GIVEN ME!
         
        if (!IsPostBack && Request.QueryString["xval1"] == null)
         {
             CountryDropDownControl.DataTextField = "ReportCountry";
             CountryDropDownControl.DataValueField = "ReportCountry";
             CountryDropDownControl.DataSource = CountryDropDownList;
             CountryDropDownControl.DataBind();
             CountryDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
             CountryDropDownControl.SelectedIndex = CountryDropDownControl.Items.IndexOf(CountryDropDownControl.Items.FindByValue("Choose One"));
 
         }
         else if (!IsPostBack && Request.QueryString["xval1"] != null)
         {
             //this populates the country control and preselects the country they selected
 
             CountryDropDownControl.DataTextField = "ReportCountry";
             CountryDropDownControl.DataValueField = "ReportCountry";
             CountryDropDownControl.DataSource = CountryDropDownList;
             CountryDropDownControl.DataBind();
 
             
            
             CountryDropDownControl.SelectedIndex = CountryDropDownControl.Items.IndexOf(CountryDropDownControl.Items.FindByValue(Request.Form[hdnCountry.Value]));
 
             //now populate the area dropdown based on the country again.
             AreaDropDownControl.DataTextField = "Area";
             AreaDropDownControl.DataValueField = "Area";
             AreaDropDownControl.DataSource = AreaDropDownList; //be sure that this method is getting the latest country selected (if not, use the hidden value on your page to query the db.)
             AreaDropDownControl.DataBind();
             AreaDropDownControl.Items.Add(new ListItem("Choose One", "Choose One"));
             AreaDropDownControl.SelectedIndex = AreaDropDownControl.Items.IndexOf(AreaDropDownControl.Items.FindByValue("Choose One"));
         }

Open in new window

0
 
djshohitAuthor Commented:
Did you mean
CountryDropDownControl.Attributes.Add("onchange", "setVal(this.value)");
 
instead of CountryDropDownList?
0
 
clintfieldCommented:
Probably....  ;-)
0
 
djshohitAuthor Commented:
Ok to make life much easier, cause I dont want to hog up anymore of your time. Here is the URL for the sample application.
http://docs.google.com/Doc?id=djk8gmz_55ccdfb8dj
Once you go there, you'll see the URL. Click on that and play around. You'll get the feel of how things are. Oh and btw, the credit for all this goes to you :)
0
 
djshohitAuthor Commented:
CountryDropDownList is a datasource and CountryDropDownControl is the drop down menu itself. CountryDropDownList doesnt have an Attributes method but the CountryDropDownControl does.
Anyways long story short - that didnt help either. The hidden field isnt catching the Value clicked in the country I think!
0
 
clintfieldCommented:
Try this.  Put an alert in the javascript to see what is happening.
 function setVal(val)
  {
     
    alert(val);
    aspnetForm.hdnCountry.value=val;
     
 
  }  
 
Also, make sure the countrydown control is set to autopostback.
0
 
djshohitAuthor Commented:
Aah Screw it! I'll use the Request.QueryString...always works! Just added an extra &country. Just need to make sure it works! And I think we're done!
Cant thank you enough. Learned a lot dude - hell Request.QueryString is definitely a useful thing to learn! I'll award you points. Maybe I'll have a few other question on dundas charts in the near future. I'll post a link for the question here. Hopefully it wont be too long as this one.
Thank you once again!
0
 
clintfieldCommented:
Dont forget using session vars too.  You can store vals in there pretty easily.  
Session.Add("country",countrydropdown.selectedvalue);
 
Good luck with the project.  I hope you can use some of these comments for future reference.  The data you work with looks interesting.  I have a degree in Economics so my curiosity is piqued as to what you are using this stuff for...
0
 
djshohitAuthor Commented:
Thankyou for all your help!!!! i'll come back for anything else. I'll probably post the link to anything else I might need help with over here.

Thank you :)
0
 
djshohitAuthor Commented:
Here's the URl for your interest:
 http://docs.google.com/Doc?id=djk8gmz_56c2pxjccf
its basically data to be used internally for the company. Browse around and enjoy while its up there. :)
I have a quick question :). How do I add the Choose One item to either appear on top of the drop down, OR remove it completly whenever the user clicks on the arrow next to the drop down!
 
0
 
clintfieldCommented:
I think the way we did it, Choose One will always be the last item in the list, even if it appears pre selected.  I do have a class file that I created which allows you to compile it and use it as a dropdownlist in your apps.  It allows you to set a property for default selected value and text.  It also allows you to set colors in the dropdown, etc.  I can post it if you know how to create a project in which you can compile it and use it your apps.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 56
  • 37
Tackle projects and never again get stuck behind a technical roadblock.
Join Now