asp.net傳多個值到其它頁面的具體實現(xiàn)
更新時間:2014年02月21日 16:24:18 作者:
在頁面之間的跳轉(zhuǎn),經(jīng)常會用到傳值,其中可能會傳遞多個值,下面為大家介紹下asp.net傳多個值到其它頁面的方法,需要的朋友可以參考下
網(wǎng)站開發(fā)中,在頁面之間的跳轉(zhuǎn),經(jīng)常會用到傳值,其中可能會傳遞多個值。
一、CommadArgument傳多個值到其他頁面。
像Gridview dataList repeater等數(shù)據(jù)綁定控件中,可以使用CommadArgument傳多個值。
源的代碼(aspx頁面代碼)如下:這個代碼一般寫在項模板中,如果你用的第一種方法就不需要加上onclick事件,直接點擊數(shù)據(jù)綁定控件的RowCommand ,itemCommand事件,就行了。
<asp:ImageButton ID="editImageButton" runat="server" ImageUrl="~/images/bt_edit.gif" CommandArgument='<%#Eval("dict_id")+","+Eval("dict_type")%>' onclick="editImageButton_Click" Height="20" Width="20" />
方法1,如果你用的GridView 控件,找到RowCommand事件雙擊,用的dataList,repeater控件就找到ItemCommand事件雙擊,后臺代碼如下:
object[] arg=e.CommandArgument.ToString().split(','); //注意是單引號
string arg0=arg[0].ToString();
string arg1=arg[1].ToString();
方法2,在項模板中放入LinkButton控件。這個比較常用,自己動手給這個控件加上onClick事件。其后臺代碼如下:
LinkButton lbt=(LinkButton)sender;
object[] arg=lbt.CommandArgument.ToString.split(',');
string arg0=arg[0].ToString();
string arg1=arg[1].ToString();
二、用超鏈接傳值,也是一種常用的方法
前臺代碼:
<a href="Default.aspx?id=<%#Eval("dict_id")%>&type=<%#Eval("dict_type")%>">跳到Default.aspx頁面</a>
后臺:
string strDict_id = Request.QueryString["dict_id"];
string strDict_type= Request.QueryString["dict_type"];
一、CommadArgument傳多個值到其他頁面。
像Gridview dataList repeater等數(shù)據(jù)綁定控件中,可以使用CommadArgument傳多個值。
源的代碼(aspx頁面代碼)如下:這個代碼一般寫在項模板中,如果你用的第一種方法就不需要加上onclick事件,直接點擊數(shù)據(jù)綁定控件的RowCommand ,itemCommand事件,就行了。
復(fù)制代碼 代碼如下:
<asp:ImageButton ID="editImageButton" runat="server" ImageUrl="~/images/bt_edit.gif" CommandArgument='<%#Eval("dict_id")+","+Eval("dict_type")%>' onclick="editImageButton_Click" Height="20" Width="20" />
方法1,如果你用的GridView 控件,找到RowCommand事件雙擊,用的dataList,repeater控件就找到ItemCommand事件雙擊,后臺代碼如下:
復(fù)制代碼 代碼如下:
object[] arg=e.CommandArgument.ToString().split(','); //注意是單引號
string arg0=arg[0].ToString();
string arg1=arg[1].ToString();
方法2,在項模板中放入LinkButton控件。這個比較常用,自己動手給這個控件加上onClick事件。其后臺代碼如下:
復(fù)制代碼 代碼如下:
LinkButton lbt=(LinkButton)sender;
object[] arg=lbt.CommandArgument.ToString.split(',');
string arg0=arg[0].ToString();
string arg1=arg[1].ToString();
二、用超鏈接傳值,也是一種常用的方法
前臺代碼:
復(fù)制代碼 代碼如下:
<a href="Default.aspx?id=<%#Eval("dict_id")%>&type=<%#Eval("dict_type")%>">跳到Default.aspx頁面</a>
后臺:
復(fù)制代碼 代碼如下:
string strDict_id = Request.QueryString["dict_id"];
string strDict_type= Request.QueryString["dict_type"];
相關(guān)文章
把a(bǔ)spx頁面?zhèn)窝b成靜態(tài)html格式的實現(xiàn)代碼
把a(bǔ)spx頁面?zhèn)窝b成靜態(tài)html格式的實現(xiàn)代碼,主要是利于搜索引擎的收錄。2011-10-10
Request.QueryString與一般NameValueCollection的區(qū)別
最近在做一個搜索程序的優(yōu)化改進(jìn),將搜索結(jié)果按照查詢的參數(shù)不同進(jìn)行緩存。緩存的Key很自然的就想到了用查詢字符串,而獲取查詢字符串的最簡單方式是通過Request.QueryString.ToString()方法2011-12-12
利用FastReport傳遞圖片參數(shù)在報表上展示簽名信息的實現(xiàn)方法
這篇文章主要介紹了利用FastReport傳遞圖片參數(shù)在報表上展示簽名信息,其中主要注意的是,我們傳遞的圖片數(shù)據(jù)需要采用Base64String的格式才能正常傳遞和展示,本文通過圖文實例代碼相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-10-10
ASP.NET中Validation驗證控件正則表達(dá)式特殊符號的說明
本文介紹asp.net中RegularExpressionValidator控件中的幾種特殊字符串使用規(guī)則,并做了代碼演示,希望對大家有所幫助。2016-04-04

