开发者

Assigning a session variable into DetailsView

开发者 https://www.devze.com 2023-03-27 08:24 出处:网络
I have a Session Variable declared and checked that it exists. I would like the DetailsView to display the Session Variable number in the INSERT Textbox in the DetailsView. When the Insert Button is p

I have a Session Variable declared and checked that it exists. I would like the DetailsView to display the Session Variable number in the INSERT Textbox in the DetailsView. When the Insert Button is pressed I, require the record in the DetailsView to be despatched to the database, to create an additional record. From the experimentation I have carried out, it appears to be difficult to penetrate the DetailsView. I imagine that there is a requirement for some "Code Behi开发者_StackOverflow中文版nd" to be included.


You need to use the detailsview Databound event and assign the value to the textbox. e.g.

protected void DetailsView1_DataBound(object sender, EventArgs e)
{
 if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
 {
    TextBox TextBox1 = DetailsView1.FindControl("TextBox1") as TextBox;
    TextBox1.Text = Session["Name"].ToString();
 }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号