0

I have a SqlDataSource that updates whenever a user specifies a value. I'm trying to do the following to update the gridview as well, but the gridview won't show anything. Did I miss anything here?

private void updateSessionGridView(string p)
{
    session.SelectCommand = @"SELECT TOP 10  * FROM [MyDB]
                                    where key = '" + p + "'";
    GridView1.DataSourceID = null; 
    GridView1.DataSource = session;
    GridView1.DataBind();
} 
3
  • Is this for ASP.Net or WinForms? Commented Mar 14, 2012 at 0:40
  • for ASP.net. I enabled the AutoGenerateSelectButton. Only 10 "Select" column is shown but no actual data. Commented Mar 14, 2012 at 0:50
  • Please don't prefix your titles with "C#" and such. That's what the tags are for. Commented Mar 14, 2012 at 1:18

1 Answer 1

1

If you are using a data source control, then you need to set the DataSourceID property, not the DataSource property.

Sign up to request clarification or add additional context in comments.

3 Comments

Unfortunately it doesn't work either when I change the code to GridView1.DataSource = session.ID
No, do not set DataSource. See `DataSourceID'.
I've edited the answer. If you want to remove the downvote, you should be able now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.