gridview中的ASP.NET重定向页面selectedindexchanged

时间:2015-02-18 05:42:20

标签: c# asp.net redirect gridview

大家好我想问一下如何使用selectedindexchanged

从另一个页面重定向

我的HTML代码看起来像这样

<asp:GridView ID="gridsummary" runat="server" AutoGenerateColumns="False" EnableModelValidation="True"
                HorizontalAlign="Left" OnSelectedIndexChanged="gridsummary_SelectedIndexChanged">
               <Columns>
                   <asp:BoundField DataField="sstat" HeaderText="STATUS">
                   <ItemStyle Width="250px" HorizontalAlign="Left" VerticalAlign="Top" />
                   </asp:BoundField>
                   <asp:BoundField DataField="ctr" HeaderText="COUNT" >
                   <ItemStyle HorizontalAlign="Center" VerticalAlign="Top" Width="150px" />
                   </asp:BoundField>
                   <asp:TemplateField>
        <ItemTemplate>
            <asp:LinkButton Text="Select" ID="lnkSelect" runat="server" CommandName="Select" />
        </ItemTemplate>
    </asp:TemplateField>
               </Columns>
               <HeaderStyle CssClass="GRIDVIEW_TITLE" />
               <RowStyle CssClass="GRIDVIEW_DETAILS" />
            </asp:GridView>

我的OnSelectedIndexChanged中有一个像这样的代码

protected void gridsummary_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = gridsummary.SelectedRow;
        string sStat = row.Cells[0].Text;


    }

我想要的是if sStat='Delivered'它将被重定向到此页面webViewDelivered.aspxif sStat='For Processing'它将被重定向到另一个页面。有没有办法在SelectedIndexChanged中做到这一点?或者我可以在selectedindexchanged上添加一个属性,以便我可以拥有<a href='webViewDelivered.aspx'/>

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您可以使用Response.Redirect重定向到所需的网页。Here is more info.

   protected void gridsummary_SelectedIndexChanged(object sender, EventArgs e)
   {
    GridViewRow row = gridsummary.SelectedRow;
    if(row.Cells[0].Text.Equals("Delivered"))
    {
           Response.Redirect("\webViewDelivered.aspx");
    }
    else if(row.Cells[0].Text.Equals("For Processing"))
    {
           Response.Redirect("\Anathoryourpage.aspx");
    }
   }