Could DataGridView be this dumb? or its me?lol

Posted by Selase on Stack Overflow See other posts from Stack Overflow or by Selase
Published on 2011-01-15T18:44:40Z Indexed on 2011/01/15 18:53 UTC
Read the original article Hit count: 236

Filed under:
|

Am trying to bind data to a dropdown list on pageload based on a condition. Code explains further below.

public partial class AddExhibit : System.Web.UI.Page
{
    string adminID, caseIDRetrieved;

    DataSet caseDataSet = new DataSet();
    SqlDataAdapter caseSqlDataAdapter = new SqlDataAdapter();
    string strConn = WebConfigurationManager.ConnectionStrings["CMSSQL3ConnectionString1"].ConnectionString;

    protected void Page_Load(object sender, EventArgs e)
    {
        adminID = Request.QueryString["adminID"];
        caseIDRetrieved = Request.QueryString["caseID"];

        if (caseIDRetrieved != null)
        {
            CaseIDDropDownList.Text = caseIDRetrieved;
            //CaseIDDropDownList.Enabled = false;

        }
        else
        {
            try
            {
                CreateDataSet();
                DataView caseDataView = new DataView(caseDataSet.Tables[0]);
                CaseIDDropDownList.DataSource = caseDataView;
                CaseIDDropDownList.DataBind();
            }
            catch (Exception ex)
            {
                string script = "<script>alert('" + ex.Message + "');</script>";
            }

        }


    }

The CreateDataset method that is called in the if..else statement is contains the following code.

private void CreateDataSet()
    {
        SqlConnection caseConnection = new SqlConnection(strConn);
        caseSqlDataAdapter.SelectCommand = new SqlCommand("Select CaseID FROM Cases", caseConnection);
        caseSqlDataAdapter.Fill(caseDataSet);
    }

However when i load the page and as usual the condition that is supposed to bid the data is met, the gridview decides to displays as follows... alt text

IS IT ME OR ITS THE DATAGRID?...??

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET