Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Unbind - bind gridview

dwg86dwg86 Posts: 15Member
I've created a gridview in VWD2005 and bound it to an AccessDatasource in the designer mode. (i.e. using a sort of wizard). What I want to do is change the data sources' SELECT command to view a different table in the gridview. I'm trying the "gridview1.datasource = nothing" and the "gridview1.databind()".. but all in vain.

Please help. I've searched all over the net but haven't really understood much posts about this. Thanks a million!

Daniel

Comments

  • shinsnakeshinsnake Posts: 93Member
    [b][red]This message was edited by shinsnake at 2006-8-25 16:29:11[/red][/b][hr]
    I'm no expert on this, but this is what I did.

    When I checked to see if a user existed, it would call a custom function that binded the gridview:

    [code]protected void btnCheck_Click(object sender, EventArgs e)
    {
    strFirstName = txtFirstName.Text.ToString();
    strLastName = txtLastName.Text.ToString();
    SqlCommand sqlComm = new SqlCommand("SELECT User_ID, FirstName, LastName, Income FROM UserInfo WHERE " +
    "(FirstName = '" + strFirstName + "') AND (LastName = '" + strLastName + "')", connBudget);
    SqlDataReader sdrUser;
    connBudget.Open();
    sdrUser = sqlComm.ExecuteReader();

    if (sdrUser.Read())
    {
    txtFirstName.Text = sdrUser[1].ToString();
    txtLastName.Text = sdrUser[2].ToString();
    txtYrlyInc.Text = sdrUser[3].ToString();
    nUserID = Convert.ToInt16(sdrUser[0].ToString());
    }
    else
    {
    lblUserExist.Text = "User Does Not Exist!";
    lblUserExist.Visible = true;
    }
    connBudget.Close();

    gvBudgetInfo_DataBind();
    txtCompleted.Text = "1";
    }

    protected void gvBudgetInfo_DataBind()
    {
    SqlCommand commBillInfo = new SqlCommand("SELECT Bill_ID, User_ID, Bill, BillCost, BillPeriod FROM BillInfo " +
    "WHERE (User_ID = " + nUserID + ")", connBudget);
    DataSet dsBillInfo = new DataSet();
    SqlDataAdapter sdaBillInfo = new SqlDataAdapter(commBillInfo);
    sdaBillInfo.Fill(dsBillInfo);

    DataView dv = dsBillInfo.Tables[0].DefaultView;

    if (ViewState["sortexpression"] != null)
    {
    dv.Sort = ViewState["sortexpression"].ToString()
    + " " + ViewState["sortdirection"].ToString();
    }

    gvBudgetInfo.DataSource = dsBillInfo;
    gvBudgetInfo.DataBind();
    Calculations();
    }[/code]

    The sort code doesn't work, so ignore that, but I basically create a dataset every time that comes from the database, then set it to the source of the gridview and then bind it. I had the same problem that I think you are having and the only way I could get it to work was to write everything from scratch and not use any of the wizards. I'm pretty sure the above code will only work if you don't assign the gridview a datasource. Hope that helps.

    : I've created a gridview in VWD2005 and bound it to an AccessDatasource in the designer mode. (i.e. using a sort of wizard). What I want to do is change the data sources' SELECT command to view a different table in the gridview. I'm trying the "gridview1.datasource = nothing" and the "gridview1.databind()".. but all in vain.
    :
    : Please help. I've searched all over the net but haven't really understood much posts about this. Thanks a million!
    :
    : Daniel
    :



  • shamim104shamim104 Posts: 1Member
    : I've created a gridview in VWD2005 and bound it to an AccessDatasource in the designer mode. (i.e. using a sort of wizard). What I want to do is change the data sources' SELECT command to view a different table in the gridview. I'm trying the "gridview1.datasource = nothing" and the "gridview1.databind()".. but all in vain.
    :
    : Please help. I've searched all over the net but haven't really understood much posts about this. Thanks a million!
    :
    : Daniel
    :

    You should do this:
    gridview1.DataSourceID = Nothing or null in c#
    gridview1.DataBind()

    and in other place that you need, should set it a gain with AccessDatasource
Sign In or Register to comment.