日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

ViewState的使用

發布時間:2025/7/14 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ViewState的使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前臺部分:布局如圖所示:?

<div>
???
??????? 請輸入標題:<asp:TextBox ID="TextBox1" runat="server" Width="178px"></asp:TextBox>
??????? <br />
??????? 請輸入內容:<asp:TextBox ID="TextBox2" runat="server" Height="131px"
??????????? TextMode="MultiLine" Width="180px"></asp:TextBox>
??????? <br />
??????? <br />
??????? <asp:Button ID="btnsave" runat="server" Text="保存" οnclick="btnsave_Click" />
??????? <asp:Button ID="btnselect" runat="server" Text="查詢" οnclick="btnselect_Click" />
???
??? </div>

------------------后臺部分

?? protected void btnsave_Click(object sender, EventArgs e)
??????? {
??????????? Gushi gushi = new Gushi();
??????????? gushi.Title = TextBox1.Text;
??????????? gushi.Content = TextBox2.Text;
??????????? if (ViewState["gushi"] != null)
??????????? {
??????????????? //將ViewStae中存儲的List<Gushi>對象取出來
??????????????? List<Gushi> list = ViewState["gushi"] as List<Gushi>;
??????????????? //將新的內容添加到List<Gushi>中
??????????????? list.Add(gushi);
??????????????? ViewState["gushi"] = list;
??????????? }
??????????? else
??????????? {
??????????????? List<Gushi> list = new List<Gushi>();
??????????????? list.Add(gushi);
??????????????? ViewState["gushi"] = list;
??????????? }
??????????? TextBox1.Text = string.Empty;
??????????? TextBox2.Text = string.Empty;
??????? }

??????? protected void btnselect_Click(object sender, EventArgs e)
??????? {
??????????? TextBox2.Text = string.Empty;
??????????? if(ViewState["gushi"]!=null)
??????????? {
??????????? List<Gushi> list=ViewState["gushi"] as List<Gushi>;
??????????? foreach (Gushi item in list)
??????????? {
??????????????? if(item.Title==TextBox1.Text)
??????????????? {
??????????????????? TextBox2.Text = item.Content;
??????????????? }
??????????? }
??????????? }
??????? }

程序運行后,我在標框看中輸入php,下面也輸入內容,然后輸入net,同樣輸入內容,然后再回來查詢php,

查詢結果如圖所示:

轉載于:https://www.cnblogs.com/qzc900809/archive/2013/04/02/2996693.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的ViewState的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。