Web application design query

  • Hello,

    I am new to web application designing and using .net (MS Visual Studio 2010) to design an application.

    The issue I have is to display information on a table based upon the 2 values selected by the user in the drop down lists. When the user presses the Find button, the results should be displayed in the form of a table from a table.

    Could someone please tell what component (table or ???) I need to select from the list and what code would need to be written to associate the 'Find' button to the table.

    Thanks inadvance for your help. Please find the screenshot for the application attached.

    Thanks,

    Paul

  • pwalter83 (1/28/2013)


    Hello,

    I am new to web application designing and using .net (MS Visual Studio 2010) to design an application.

    The issue I have is to display information on a table based upon the 2 values selected by the user in the drop down lists. When the user presses the Find button, the results should be displayed in the form of a table from a table.

    Could someone please tell what component (table or ???) I need to select from the list and what code would need to be written to associate the 'Find' button to the table.

    Thanks inadvance for your help. Please find the screenshot for the application attached.

    Thanks,

    Paul

    I don't quite understand your question here. You have two comboboxes. I assume you want to run a query that is something like "select Columns from MyTable where Col1 = Combobox 1 and Col2 - Combobox 2"?

    I don't understand what you mean about associating the Find button to a table. The button will fire a click event. That click event will do something based on the values in your comboboxes.

    If you can try to explain what your question/confusion is I can try to help.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (1/28/2013)


    pwalter83 (1/28/2013)


    Hello,

    I am new to web application designing and using .net (MS Visual Studio 2010) to design an application.

    The issue I have is to display information on a table based upon the 2 values selected by the user in the drop down lists. When the user presses the Find button, the results should be displayed in the form of a table from a table.

    Could someone please tell what component (table or ???) I need to select from the list and what code would need to be written to associate the 'Find' button to the table.

    Thanks inadvance for your help. Please find the screenshot for the application attached.

    Thanks,

    Paul

    I don't quite understand your question here. You have two comboboxes. I assume you want to run a query that is something like "select Columns from MyTable where Col1 = Combobox 1 and Col2 - Combobox 2"?

    I don't understand what you mean about associating the Find button to a table. The button will fire a click event. That click event will do something based on the values in your comboboxes.

    If you can try to explain what your question/confusion is I can try to help.

    Thanks for your reply. The query you mentioned is exactly I wish to write but it should be executed when the 'Find' button is clicked.

    The results from the query then should be displayed in a table format having several columns depending upon the 2 values selected by the user.

  • OK easy enough. As I said previously you will need to use an event of the button. Since you want this to happen when the user clicks the button, you will use the click event.

    Just add code to your click event to run your query. Stick the results of your query into a datatable and bind your gridview to the datatable.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (1/28/2013)


    OK easy enough. As I said previously you will need to use an event of the button. Since you want this to happen when the user clicks the button, you will use the click event.

    Just add code to your click event to run your query. Stick the results of your query into a datatable and bind your gridview to the datatable.

    Thanks Sean,

    Do I need to add the code to the 'OnClientClick' property ? This is the only property I can see on the list.

    Also, I cannot find the component 'datatable', is it the same as 'Table' ?

    lastly, do you refer to gridview as the component or as a property ?

    Sorry for the botheration.

    Thanks.

  • pwalter83 (1/28/2013)


    Sean Lange (1/28/2013)


    OK easy enough. As I said previously you will need to use an event of the button. Since you want this to happen when the user clicks the button, you will use the click event.

    Just add code to your click event to run your query. Stick the results of your query into a datatable and bind your gridview to the datatable.

    Thanks Sean,

    Do I need to add the code to the 'OnClientClick' property ? This is the only property I can see on the list.

    Also, I cannot find the component 'datatable', is it the same as 'Table' ?

    lastly, do you refer to gridview as the component or as a property ?

    Sorry for the botheration.

    Thanks.

    I am going to guess you don't know much about web development. The OnClientClick event is the client side event for clicking. You want the server side event (unless you are going to do this via jquery).

    DataTable belongs to the System.Data namespace. I don't know how you are querying your data. If you are using a SqlDataSource you will have to add parameters to the select property and requery server side.

    The GridView is what you will use to display the results of your query.

    I would highly recommend you dig around and find some tutorials on basic asp.net development. Not trying to sound rude but you really need to understand what you are doing and from your posts it seems you are very unfamiliar with how this stuff works. Web development is quite different than windows applications because you have code that runs on the server and code that runs on the client and you have to deal with both.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (1/28/2013)


    pwalter83 (1/28/2013)


    Sean Lange (1/28/2013)


    OK easy enough. As I said previously you will need to use an event of the button. Since you want this to happen when the user clicks the button, you will use the click event.

    Just add code to your click event to run your query. Stick the results of your query into a datatable and bind your gridview to the datatable.

    Thanks Sean,

    Do I need to add the code to the 'OnClientClick' property ? This is the only property I can see on the list.

    Also, I cannot find the component 'datatable', is it the same as 'Table' ?

    lastly, do you refer to gridview as the component or as a property ?

    Sorry for the botheration.

    Thanks.

    I am going to guess you don't know much about web development. The OnClientClick event is the client side event for clicking. You want the server side event (unless you are going to do this via jquery).

    DataTable belongs to the System.Data namespace. I don't know how you are querying your data. If you are using a SqlDataSource you will have to add parameters to the select property and requery server side.

    The GridView is what you will use to display the results of your query.

    I would highly recommend you dig around and find some tutorials on basic asp.net development. Not trying to sound rude but you really need to understand what you are doing and from your posts it seems you are very unfamiliar with how this stuff works. Web development is quite different than windows applications because you have code that runs on the server and code that runs on the client and you have to deal with both.

    Thanks Sean,

    I have come to a point where I need to add the sql code within this:

    ---------------------------------------

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    End Sub

    ---------------------------------------

    The SQL code would be as you suggested- "select Columns from MyTable where Col1 = Combobox 1 and Col2 = Combobox 2" but I dont know what vb.net syntax I need to enter this in.

    Any suggestions would be welcome. Thanks,

    Paul

  • pwalter83 (1/29/2013)


    Thanks Sean,

    I have come to a point where I need to add the sql code within this:

    ---------------------------------------

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    End Sub

    ---------------------------------------

    The SQL code would be as you suggested- "select Columns from MyTable where Col1 = Combobox 1 and Col2 = Combobox 2" but I dont know what vb.net syntax I need to enter this in.

    Any suggestions would be welcome. Thanks,

    Paul

    I would make two suggestions. First give your button a name that means something. Button1 is like calling a column Column1 in sql, maybe something like btnSearch. Not naming your controls is a habit that is really tough to break unless you start early.

    Secondly, don't run that sql code. Instead execute a stored procedure and pass the combobox values as parameters. Look up the syntax with google/bing/whatever. There are a number of ways to query data from the database with .NET.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (1/29/2013)


    pwalter83 (1/29/2013)


    Thanks Sean,

    I have come to a point where I need to add the sql code within this:

    ---------------------------------------

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    End Sub

    ---------------------------------------

    The SQL code would be as you suggested- "select Columns from MyTable where Col1 = Combobox 1 and Col2 = Combobox 2" but I dont know what vb.net syntax I need to enter this in.

    Any suggestions would be welcome. Thanks,

    Paul

    I would make two suggestions. First give your button a name that means something. Button1 is like calling a column Column1 in sql, maybe something like btnSearch. Not naming your controls is a habit that is really tough to break unless you start early.

    Secondly, don't run that sql code. Instead execute a stored procedure and pass the combobox values as parameters. Look up the syntax with google/bing/whatever. There are a number of ways to query data from the database with .NET.

    Slowly but not steadily, I have reached here now:

    ---------------------------------------------------------------

    using System;

    using System.Data;

    using System.Collections.Generic;

    using System.Data.SqlClient;

    using System.Globalization;

    using System.Text.RegularExpressions;

    using System.Security.Principal; // here is the security namespace you need

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    protected void Button1_Click(object sender, EventArgs e)

    {

    DataTable dt = new DataTable();

    SqlConnection connection = new SqlConnection("YOUR CONNECTION STRING HERE");

    connection.Open();

    SqlCommand sqlCmd = new SqlCommand("SELECT Office_cd,Trade_cd, system_name, interface_direction, last_update_dt FROM header WHERE office_cd = @Value1 AND trade_cd =@Value2", connection);

    SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);

    sqlCmd.Parameters.AddWithValue("@Value1", Office_cd.SelectedItem.Text);

    sqlCmd.Parameters.AddWithValue("@Value2", trade_cd.SelectedItem.Text);

    sqlDa.Fill(dt);

    if (dt.Rows.Count > 0)

    {

    TextBox1.Text = dt.Rows[0]["Office_cd"].ToString();

    //Where ColumnName is the Field from the DB that you want to display

    TextBox2.Text = dt.Rows[0]["Trade_cd"].ToString();

    }

    connection.Close();

    }

    ------------------------------------------------------------

    However, I am now getting this error on Datatable- Error 1 The type or namespace name 'DataTable' could not be found (are you missing a using directive or an assembly reference?) . Inspite of including 'using System.Data;' reference, I get this error, would you know how it can be corrected ?

    Thanks

  • pwalter83 (1/30/2013)


    Sean Lange (1/29/2013)


    pwalter83 (1/29/2013)


    Thanks Sean,

    I have come to a point where I need to add the sql code within this:

    ---------------------------------------

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    End Sub

    ---------------------------------------

    The SQL code would be as you suggested- "select Columns from MyTable where Col1 = Combobox 1 and Col2 = Combobox 2" but I dont know what vb.net syntax I need to enter this in.

    Any suggestions would be welcome. Thanks,

    Paul

    I would make two suggestions. First give your button a name that means something. Button1 is like calling a column Column1 in sql, maybe something like btnSearch. Not naming your controls is a habit that is really tough to break unless you start early.

    Secondly, don't run that sql code. Instead execute a stored procedure and pass the combobox values as parameters. Look up the syntax with google/bing/whatever. There are a number of ways to query data from the database with .NET.

    Slowly but not steadily, I have reached here now:

    ---------------------------------------------------------------

    using System;

    using System.Data;

    using System.Collections.Generic;

    using System.Data.SqlClient;

    using System.Globalization;

    using System.Text.RegularExpressions;

    using System.Security.Principal; // here is the security namespace you need

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    protected void Button1_Click(object sender, EventArgs e)

    {

    DataTable dt = new DataTable();

    SqlConnection connection = new SqlConnection("YOUR CONNECTION STRING HERE");

    connection.Open();

    SqlCommand sqlCmd = new SqlCommand("SELECT Office_cd,Trade_cd, system_name, interface_direction, last_update_dt FROM header WHERE office_cd = @Value1 AND trade_cd =@Value2", connection);

    SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);

    sqlCmd.Parameters.AddWithValue("@Value1", Office_cd.SelectedItem.Text);

    sqlCmd.Parameters.AddWithValue("@Value2", trade_cd.SelectedItem.Text);

    sqlDa.Fill(dt);

    if (dt.Rows.Count > 0)

    {

    TextBox1.Text = dt.Rows[0]["Office_cd"].ToString();

    //Where ColumnName is the Field from the DB that you want to display

    TextBox2.Text = dt.Rows[0]["Trade_cd"].ToString();

    }

    connection.Close();

    }

    ------------------------------------------------------------

    However, I am now getting this error on Datatable- Error 1 The type or namespace name 'DataTable' could not be found (are you missing a using directive or an assembly reference?) . Inspite of including 'using System.Data;' reference, I get this error, would you know how it can be corrected ?

    Thanks

    Thanks Sean, resolved this by changing to .NET Framework 4.0.

  • pwalter83 (1/30/2013)


    Sean Lange (1/29/2013)


    pwalter83 (1/29/2013)


    Thanks Sean,

    I have come to a point where I need to add the sql code within this:

    ---------------------------------------

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    End Sub

    ---------------------------------------

    The SQL code would be as you suggested- "select Columns from MyTable where Col1 = Combobox 1 and Col2 = Combobox 2" but I dont know what vb.net syntax I need to enter this in.

    Any suggestions would be welcome. Thanks,

    Paul

    I would make two suggestions. First give your button a name that means something. Button1 is like calling a column Column1 in sql, maybe something like btnSearch. Not naming your controls is a habit that is really tough to break unless you start early.

    Secondly, don't run that sql code. Instead execute a stored procedure and pass the combobox values as parameters. Look up the syntax with google/bing/whatever. There are a number of ways to query data from the database with .NET.

    Slowly but not steadily, I have reached here now:

    ---------------------------------------------------------------

    using System;

    using System.Data;

    using System.Collections.Generic;

    using System.Data.SqlClient;

    using System.Globalization;

    using System.Text.RegularExpressions;

    using System.Security.Principal; // here is the security namespace you need

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    protected void Button1_Click(object sender, EventArgs e)

    {

    DataTable dt = new DataTable();

    SqlConnection connection = new SqlConnection("YOUR CONNECTION STRING HERE");

    connection.Open();

    SqlCommand sqlCmd = new SqlCommand("SELECT Office_cd,Trade_cd, system_name, interface_direction, last_update_dt FROM header WHERE office_cd = @Value1 AND trade_cd =@Value2", connection);

    SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);

    sqlCmd.Parameters.AddWithValue("@Value1", Office_cd.SelectedItem.Text);

    sqlCmd.Parameters.AddWithValue("@Value2", trade_cd.SelectedItem.Text);

    sqlDa.Fill(dt);

    if (dt.Rows.Count > 0)

    {

    TextBox1.Text = dt.Rows[0]["Office_cd"].ToString();

    //Where ColumnName is the Field from the DB that you want to display

    TextBox2.Text = dt.Rows[0]["Trade_cd"].ToString();

    }

    connection.Close();

    }

    ------------------------------------------------------------

    However, I am now getting this error on Datatable- Error 1 The type or namespace name 'DataTable' could not be found (are you missing a using directive or an assembly reference?) . Inspite of including 'using System.Data;' reference, I get this error, would you know how it can be corrected ?

    Thanks

    I am able to display the values in the gridview now but it shows up all the values that are in the table. My requirement is to only show data based upon the values selected by the user from the 2 drop down lists and then pressing the 'Find' button.

    The code in the click event of the 'Find' button seems to be okay to display the filtered values but it still doesnt work. Please find the code attached.using System;

    using System.Data;

    using System.Configuration;

    using System.Collections.Generic;

    using System.Data.SqlClient;

    using System.Globalization;

    using System.Text.RegularExpressions;

    using System.Security.Principal; // here is the security namespace you need

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    namespace GISA

    {

    public partial class _Default : System.Web.UI.Page

    {

    private string GetConnectionString()

    {

    return ConfigurationManager.ConnectionStrings["GISAConnectionString"].ConnectionString;

    }

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

    DataTable dt = new DataTable();

    SqlConnection connection = new SqlConnection(GetConnectionString());

    connection.Open();

    SqlCommand sqlCmd = new SqlCommand("SELECT Office_cd,Trade_cd, system_name, interface_direction, last_update_dt FROM header WHERE office_cd = @Value1 AND trade_cd =@Value2", connection);

    SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);

    sqlCmd.Parameters.AddWithValue("@Value1", Office_cd.SelectedItem.Text);

    sqlCmd.Parameters.AddWithValue("@Value2", trade_cd.SelectedItem.Text);

    sqlDa.Fill(dt);

    if (dt.Rows.Count > 0)

    {

    GridView1.DataSource = dt;

    GridView1.DataBind();

    }

    connection.Close();

    }

    protected void Button2_Click(object sender, EventArgs e)

    {

    }

    protected void Button3_Click(object sender, EventArgs e)

    {

    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

    {

    }

    protected void Office_cd_SelectedIndexChanged(object sender, EventArgs e)

    {

    }

    protected void Office_cd0_SelectedIndexChanged(object sender, EventArgs e)

    {

    }

    protected void Find_Command(object sender, CommandEventArgs e)

    {

    }

    }

    }

    Thanks.

  • The code in the click event of the 'Find' button seems to be okay to display the filtered values but it still doesnt work. Please find the code attached.

    What do you mean it doesn't work? Does it display the wrong data? Too much? Not enough? I don't see anything horribly wrong with your code. You should look at disposing your objects though so you don't have lots of work for GC to handle.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (1/31/2013)


    The code in the click event of the 'Find' button seems to be okay to display the filtered values but it still doesnt work. Please find the code attached.

    What do you mean it doesn't work? Does it display the wrong data? Too much? Not enough? I don't see anything horribly wrong with your code. You should look at disposing your objects though so you don't have lots of work for GC to handle.

    Thanks Sean. Sorry for the incomplete info. Actually my requirement is to stick the results to a gridview based on the values the users select from the 2 dropdown boxes and after they press the 'Find' button.

    However, when I view the result in a browser, it displays all the data from the table in the gridview and doesnt filter out based on the values from the 2 dropdown boxes. I think somewhere there is a link missing between the click event code of the button and the gridview. Because when I run the query in SQL, it works correctly and displays filtered data.

  • pwalter83 (1/31/2013)

    However, when I view the result in a browser, it displays all the data from the table in the gridview and doesnt filter out based on the values from the 2 dropdown boxes. I think somewhere there is a link missing between the click event code of the button and the gridview. Because when I run the query in SQL, it works correctly and displays filtered data.

    Is it possible that your current version isn't building properly, and you are running an older version of the code? If a solution doesn't build, VS will ask you if you want to run the last buildable version; you can answer Yes and opt to not be shown that warning again. This might explain why it does not appear to be processing your WHERE clause correctly.

    To be honest, the code behind your click event looks right to me. You could replace the references to @Value1/2 with hard-coded values to see if that returns the desired results; if it does, then something's wrong with the way you're populating the parameter values (though it seems to me that would result in 0 rows returned, not All).

  • Have you run this in the debugger? You can check the visible rowcount of the grid at the beginning of your method and then again at the end. Also setup a trace so you can see the actual query being sent.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic. Login to reply