Click here to Skip to main content
15,893,790 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

Hi,

you can use Query string or Session

Here's the code of gridview

XML
<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


XML
<asp:HyperLinkField DataTextField="OnCallStart" HeaderText="OncallStart"
    NavigateUrl='<%# String.Format("\details.aspx?date={0}", Eval("OncallActivityDate")) %>'> SortExpression="OnCallStart" />
 
Share this answer
 
IF you have set
C#
DataKeyNames
or
C#
DataMember

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
<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>


The GridOnCommand EventHandler is stated in this part.
In the CodeBehind you can find your selected row with the next 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");
}
 
Share this answer
 
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}" 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900