我有一个Web表单(Page1.aspx),我在其中将ID作为查询字符串传递给另一个页面(Page2.aspx)。 现在在这个页面中,我有EntityDataSource,它绑定到GridView。我该如何使用该ID填充此gridview?
EG。如果我的ID是1056,那么在Page2.aspx中的DataGridView中应该填充此ID的元素。
这是代码:
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???
}
}
我该怎么办?谢谢!
答案 0 :(得分:2)
请参阅“使用控制参数在本教程中设置”Where“属性”:
http://www.asp.net/entity-framework/tutorials/the-entity-framework-and-aspnet- - 得到启动的部分-3
除了“参数源”选择QueryString而不是Control。
之外,该过程将类似答案 1 :(得分:1)
1.从查询字符串中获取id:
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文章帮助你)在Page_load事件中。