存储gridview行值并将其显示在gridview中的另一个页面上以供登录用户使用 [英] Store gridview row values and display it on another page in gridview for a loggedin user

查看:106
本文介绍了存储gridview行值并将其显示在gridview中的另一个页面上以供登录用户使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview中有一个产品列表。在gridview中,每行都有一个复选框。每行包含汽车名称,汽车价格。我通过gridview的DataKeys属性访问carid值。我想要的是



当用户点击Book按钮我要存储时每一行的值都是我不知道如何使用并在另一页上为特定用户显示的每一行值。

我认为它类似于购物车,但我只想选择值并且没有数量这样的东西。

我想使用session.Somehow我想将列表存储在会话变量中,以便之前选择的行值可用于更新数据库。

感谢任何帮助。这是我到目前为止所做的事情



  protected   void  btnbook_Click( object  sender,EventArgs e)
{
int id = 0 ;
foreach (GridViewRow gvrow in gvcar.Rows)
{
if (((CheckBox)gvrow.FindControl( chkSelect ))。选中== true
{
var dataKey = gvcar.DataKeys [gvrow.RowIndex];
if (dataKey!= null
Response.Write(( string )( ID: + dataKey。值+ 汽车名称 + gvrow.Cells [ 1 ]文本))。
}
else
{
MessageBox.Show( 请选择汽车);
}
}
}

解决方案

创建一个类型列表,如果你已经有了汽车类,创造

列表< car> selectedList = new List< car>();

如果你没有它,创建一个类并将选定的行值添加到此列表中并将此列表绑定到另一个页面上的另一个gridview

I have a list of products in gridview.In gridview there is check box for each row. Each row contains Car Name, Car Price.I am accessing carid value thru DataKeys property of gridview .What I want is

when user clicks on Book button I want to store each row values in something which I don''t know how and use each row values to be displayed for particular user on another page.
I am thinking it analogous to shopping cart but I want only selected values and there is no such thing as quantity.
I want to do this using session.Somehow I want to store the list in session variable so that row values which are selected earlier can be used to update database.
Any help is appreciated.This is what I have done so far

protected void btnbook_Click(object sender, EventArgs e)
{
   int id = 0;
   foreach (GridViewRow gvrow in gvcar.Rows)
   {
        if (((CheckBox)gvrow.FindControl("chkSelect")).Checked == true)
        {
           var dataKey = gvcar.DataKeys[gvrow.RowIndex];
           if (dataKey != null)
              Response.Write((string) ("ID:"+dataKey.Value+"Name of Car"+gvrow.Cells[1].Text));
        }
        else
        {
           MessageBox.Show("Please select a car");
        }
    }
}

解决方案

Create a list of the type like if you already have a class for car ,create
List<car> selectedList = new List<car>();
If you don''t have it, create a class and add the selected row values to this list and bind this list to another gridview on another page


这篇关于存储gridview行值并将其显示在gridview中的另一个页面上以供登录用户使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆