如何将值存储在gridview asp.net C#中的超链接所选择的行中?

哈默德

我有一个gridview。我有一个超链接字段,我想当我单击超链接字段时,将行值存储在会话中并将页面重定向到其他页面。我怎样才能做到这一点?

这是我的aspx标记:

<asp:GridView ID="GridView1" runat="server" Height="36px" 
    style="margin-left: 270px; margin-top: 92px" Width="232px" CellPadding="3" 
    BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" 
    BorderWidth="1px" onrowcancelingedit="GridView1_RowCancelingEdit" 
    onrowediting="GridView1_RowEditing" onrowupdated="GridView1_RowUpdated" 
    onrowupdating="GridView1_RowUpdating" AutoGenerateColumns="False" 
    onrowdeleting="GridView1_RowDeleting">
    <Columns>

        <asp:TemplateField HeaderText="Table Name">
            <EditItemTemplate>
                <asp:TextBox ID="txtTBL" runat="server" Text='<%# Eval("Table_Name") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("Table_Name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>


        <asp:CommandField HeaderText="Operation" ShowEditButton="True" 
            ShowDeleteButton="True" />

        <asp:TemplateField>
        <ItemTemplate>
           <asp:HyperLink  Text="Select" ID="lnkSelect" runat="server" CommandName="Select" />
        </ItemTemplate>
    </asp:TemplateField>

    </Columns>
    <FooterStyle BackColor="White" ForeColor="#000066" />
    <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
    <RowStyle ForeColor="#000066" />
    <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#007DBB" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>

这是我的代码背后:

public partial class DisplayTable : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
         if (!Page.IsPostBack)
         {
             // Retrieve database gridview
             gettable();
         }
    }

    public void gettable()
    {
        // here is code 
    } 

    //here all code included regarding to edit,delete etc
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string s = ((HyperLink)GridView1.SelectedRow.Cells[0].Controls[0]).Text;
        Session["destype"] = s;
        Page.Response.Redirect("home.aspx");
    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        // base.VerifyRenderingInServerForm(control);
    }
}
拉胡尔·亨达维(Rahul Hendawe)

希望以下内容对您有用,不确定是否未经我的测试。

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridViewRow gr = ((sender as HyperLink).NamingContainer as GridViewRow);
    Session["destype"] = gr.Cells[0].Text.Trim(); /*For first cell value of Row */
    //Session["abc"] = gr.Cells[2].Text.Trim(); /*Repeat for other cell values of Row by increasing cell index */
    Response.Redirect("~/home.aspx");        
}

也可以使用ASP.Net中的Session变量将GridView行值发送(传递)到下一页

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将标签与表asp.net C#中的行顶部对齐

如何将AutoPostBack = true动态添加到ASP.NET C#中的按钮

如何在ASP.NET C#的Gridview中获取和显示特定值

ASP.NET是否将所选语言保留在多语言网站C#中?

如何将DbContext注入ASP.NET Core中的存储库构造函数

如何在Web应用程序中创建超链接新的ASP.NET Web表单

如何在ASP.NET C#中突出显示ActionLink的当前选择

如何将Asp.NET Button与后台代码链接?

asp net c#使用复选框获取gridview中特定行的值

如何将ASP.Net页面链接到代码?

如何将值传递给asp.net中的dropdownlist?

如何在Asp.net中的DataGrid中动态更改超链接颜色

GridView ASP.net的DataField中的超链接

如何将存储过程存储在asp.net System.Web.Caching中的缓存中

在ASP.NET中具有超链接的DIV

如何使用GridView asp.net中的复选框获取选定的行值?

超链接中的asp.net动态变量

如何将List <string>绑定到asp.net中另一个gridview内的gridview

如何在ASP.NET C#中从SQL Server到GridView中选择数据

如何将数组值传递给ASP.NET C#Web服务

如何在asp .net和c#中的gridview中启用选定的行

使用超链接ASP.Net筛选GridView

如何将多列值合并为一列?Asp.net Gridview C#

如何将HTML元素中的值分配为ASP.NET中的MVC Modal类中定义的变量的值?

如何将日志从Asp Net Core WebApi存储到Azure表存储中?

C# 在 asp.net 中禁用 GridView 标头

如何在 ASP.NET 中的 2 行下拉列表中显示所选文本?

如何将特定行中的两个值传递给 Controller asp.net core mvc?

如何将整个 http URL 传递给 asp.net API 中的存储过程?