asp. net a concrete implementation of passing multiple values to other pages

  • 2020-12-05 17:08:58
  • OfStack

In web site development, jumps between pages are often used to pass values, where multiple values may be passed.

1. CommadArgument passes multiple values to other pages.
In data-bound controls like Gridview dataList repeater, you can use CommadArgument to pass multiple values.
The source code (aspx page code) is as follows: this code is generally written in the item template, if you use the first method do not need to add onclick events, directly click the data binding control RowCommand, itemCommand events, just the line.
 
<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" /> 

Method 1, if you use GridView control, find RowCommand event double click, use dataList, repeater control find ItemCommand event double click, the background code is as follows:
 
object[] arg=e.CommandArgument.ToString().split(','); // Note the single quotation marks  
string arg0=arg[0].ToString(); 
string arg1=arg[1].ToString(); 

Method 2, put the LinkButton control in the item template. Add onClick events to this control by yourself. Its background code is as follows:
 
LinkButton lbt=(LinkButton)sender; 
object[] arg=lbt.CommandArgument.ToString.split(','); 
string arg0=arg[0].ToString(); 
string arg1=arg[1].ToString(); 

2. Using hyperlinks to pass values is also a common method
Foreground code:
 
<a href="Default.aspx?id=<%#Eval("dict_id")%>&type=<%#Eval("dict_type")%>"> Jump to the Default.aspx page </a> 

Background:
 
string strDict_id = Request.QueryString["dict_id"]; 
string strDict_type= Request.QueryString["dict_type"]; 

Related articles: