0

I have a web form (Page1.aspx) in which I am passing an ID as query string to another page (Page2.aspx). Now in this page I have EntityDataSource which binds to GridView. How should I populate this gridview with that ID?

Eg. If my ID is 1056, then in my DataGridView in Page2.aspx should populate elements of this ID.

This is the code:

 protected void Page_Load(object sender, EventArgs e)
    {
        string getEntity = Request.QueryString["EntityID"];
        int getIntEntity = Int32.Parse(getEntity);

        if (getIntEntity != 0)
        {
            //What should I do here???
        }

    }

What should I do? Thank You!

2 Answers 2

2

See "Using a Control Parameter to Set the "Where" Property" in this tutorial:

http://www.asp.net/entity-framework/tutorials/the-entity-framework-and-aspnet-–-getting-started-part-3

The process will be similar except as "Parameter source" select QueryString instead of Control.

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

1 Comment

Yes! Thank you. I did that. But I am getting this error: A property with name 'EntityID' does not exist in metadata for entity type 'EntityRegistration.FrontEnd.Entity'.
1

1.Take id from query string:

var strId = HttpContext.Current.Request.QueryString["ID"];
int id = 0;
int.TryParse(strId, out id);
if(id != 0)
{
  ...
}

2.Pass id to DataSource(mb this article help you) in Page_load event.

2 Comments

I got it. However, this does not answer my ques. If I am not mistaken I have captured that ID from previous page. Now if that ID is not NULL then what should I do?
@klm: If id not null you should pass it to datasource as parameter. Something like entityDataSource.Parameters.Add("id" .. );

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.