从 GridView 打开 Web 表单以将记录添加到 SQL 表。 C#
我不知道该怎么做。我可以使用 Response.Redirect 将 GridView 中选定行的主键值传递到下一页,但我还需要填充该行中的其他几个字段。这是我所拥有的。我想知道是否可以使用从上一页传递的主键值设置另一个文本框等于某个值。
protected void Page_Load(object sender, EventArgs e)
{
string dataKey = Request.QueryString["id"];
ProjNo.Text = dataKey;
}
I'm not sure how to go about this. I am able to pass the Primary key value from the selected row in a GridView to the next page using Response.Redirect, but I need to populate a couple other fields from that row too. Here is what I have. I want to know if I can set another textbox equal to a value using the primary key value, that was passed from the previous page.
protected void Page_Load(object sender, EventArgs e)
{
string dataKey = Request.QueryString["id"];
ProjNo.Text = dataKey;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不太清楚你想做什么,但我可以做一些观察。一旦您进入新的 Webform,原始请求中的所有上下文都会消失,除非您在 Response.Redirect() 时将其保存在某处。您有几个选项,将其放入查询字符串中:
Response.Redirect("/page.aspx?id=" + id + "&field1=" + field1);
您可以将其保存在会话中:
HttpContext.Current.Session["field1"] = field1;
Not altogether clear what you are trying to to do but i can make some observations. Once you are on the new Webform all the context from the original request has gone unless you have saved it somewhere at the time of the Response.Redirect(). You have a few options, putting it into the querystring:
Response.Redirect("/page.aspx?id=" + id + "&field1=" + field1);
You could just save it in the session:
HttpContext.Current.Session["field1"] = field1;