asp.net datagridview数据传递到另一个页面
我有2页,search.aspx和details.aspx
2,在search.aspx中,当搜索时,一个datagridview显示客户的名称和位置
3,在选择一个原始文件时,我要在detail.aspx
上显示客户的所有详细信息
怎么可能?/
我正在C#中使用storedprocedure,请使用help
I have 2 pages,search.aspx and details.aspx
2, in search.aspx, when search, a datagridview display the name and place of customer
3, on select a raw, i want to display all the details of customer on detail.aspx
How it possible?/
i am working with storedprocedure in C# pls help
您可以使用查询字符串或会话
这是gridview的代码
Hi,
you can use Query string or Session
Here''s the code of gridview
<asp:GridView ID="GridView1" runat="server" HorizontalAlign="Center"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="SchedName" HeaderText="SchedName"
SortExpression="SchedName" />
<asp:BoundField DataField="ActivityDate" HeaderText="ActivityDate"
ReadOnly="True" SortExpression="ActivityDate" />
<asp:BoundField DataField="By" HeaderText="By" SortExpression="By" />
<asp:BoundField DataField="Activity" HeaderText="Activity" ReadOnly="True"
SortExpression="Activity" />
<asp:BoundField DataField="FirstListing" HeaderText="FirstListing"
SortExpression="FirstListing" />
<asp:HyperLinkField DataTextField="OnCallStart" HeaderText="OncallStart"
NavigateUrl="details.aspx" SortExpression="OnCallStart" />
<asp:BoundField DataField="OnCallEnd" HeaderText="OnCallEnd" ReadOnly="True"
SortExpression="OnCallEnd" />
</Columns>
</asp:GridView>
或者您可以使用
Or you can use
<asp:HyperLinkField DataTextField="OnCallStart" HeaderText="OncallStart"
NavigateUrl='<%# String.Format("\details.aspx?date={0}", Eval("OncallActivityDate")) %>'> SortExpression="OnCallStart" />
如果您已设置
DataKeyNames
或
DataMember
并且您已将OnRowCommand事件添加到gridview中,然后在您的gridview OnCommand事件处理程序中,您可以:
-检查已单击的GridView行
-在Session或Viewstate中设置GridView.SeletedValue
-重定向到其他页面
-在Session或ViewState中找到SelectedValue并将此值设置为sqlparameter
与存储过程一起运行.
-将结果设置在数据集/数据表对象中,并根据需要进行处理.
示例:
在ASPX中,我在行
中有一个ImageButton控件
And you have a OnRowCommand event added to your gridview, then in your gridview OnCommand eventhandler you can:
- check the Row of GridView that was clicked
- Set the GridView.SeletedValue in Session or Viewstate
-Redirect to the other page
- Find in Session or ViewState the SelectedValue and set this value as sqlparameter
to run with your stored procedure.
- Set the result in a dataset/datatable object and do with it what you need.
Example:
In ASPX I have a ImageButton Control in the row
<code><pre lang="xml"><asp:TemplateField ItemStyle-Width="60px">
<EditItemTemplate>
<asp:ImageButton runat="server" ID="imgCancel" CssClass="GridPlaatje" ImageUrl="~/Images/NewDesign/ImageCancel16x16.png" CommandName="CancelItem" AlternateText="Cancel" OnCommand="Grid_OnCommand"/><asp:ImageButton runat="server" ID="imgSafe" CssClass="GridPlaatje" ImageUrl="~/Images/NewDesign/Accept16x16.png" CommandName="SafeItem" AlternateText="Save" OnCommand="Grid_OnCommand" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton runat="server" ID="imgEdit" CssClass="GridPlaatje" ImageUrl="~/Images/NewDesign/pencil.png" CommandName="EditGrid" AlternateText="Edit" OnCommand="Grid_OnCommand" />
</ItemTemplate>
</asp:TemplateField>
GridOnCommand EventHandler在这一部分中进行了介绍.
在背后的代码中,您可以找到具有以下代码的所选行:
The GridOnCommand EventHandler is stated in this part.
In the CodeBehind you can find your selected row with the next code:
<code><pre lang="C++">protected void Grid_OnCommand(Object sender, CommandEventArgs e)
{
lblError.Text = String.Empty;
ImageButton btn = (ImageButton)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;
String value = row.RowIndex;
Session["MyDetailValue"] = value;
Response.Redirect("someOtherPage.aspx");
}
您需要将值从gridview传递到另一页.
在网格视图上获取超链接,添加nevigateURL并发送到其他页面
You need to passvalues from gridview to another page.
Take hyperlink on grid view, add nevigateURL and send to other page
navigateurl="Detail.aspx?Rate={0};Field2={1};Field3={2}"