如何将网格视图特定的字段值以及一些值发送到数据库 [英] how to send grid view particular field value along with some values to database

查看:83
本文介绍了如何将网格视图特定的字段值以及一些值发送到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好团队,

在我的项目中,有一项要求将订单详细信息存储在数据库中.查找和选择订单详细信息的关键因素是{DealerId,DealerName,[订单详细信息..]}.
出于同样的目的,我设计了一种表格,该表格具有两个gridview,一个用于显示经销商名称,另一个用于显示订单详细信息.如果用户从第一个网格视图中选择了经销商名称,并从第二个网格视图中选择了订单详细信息,则单击保存"后,我需要将{DealerId,DealerName,[订单详细信息..]}存储到数据库中.

我的问题是:
1)如何从经销商名称中识别DealerId?
2)如何在数据库中保存两个网格选择的信息?

希望这对您有所帮助

Hello Team ,

In my project there is one requirement to store order details in database. The key factor to locate and select order details are {DealerId ,DealerName , [Order Details ..] } .
For the same I have designed one form which had two gridview one to display dealer name and another to display order details. If user have selected the dealer name from the first gridview and order details from the second grid view then on the click of SAVE I need to store {DealerId, DealerName, [Order Details ..] } on to database.

My Questions are :
1) How to identify DealerId from dealername ?
2) How to save two grids selected information in database ?

Hope this helps

推荐答案

[

"GridView"中提供了选项"DataKeyNames".
此"DataKeyNames"本身表明了它的含义.
根据您的要求,您可以在其中存储"DealerId".
代码如下所示
There is option in "GridView" to give "DataKeyNames".
This "DataKeyNames" itself suggests what it is.
For your requirement you can store the "DealerId" in it.
Code is like below
<asp:gridview id="grdDealerDetails" runat="server" autogeneratecolumns="False" allowpaging="true" datakeynames="DealerId" .....></asp:gridview>


DataKeyNames与发牌人表的主键名称相同.

并且,当您将详细信息保存到数据库时,您可以在GridView中自动获取所选行的PK.要获取"DealerId",请在RowUpdating事件中遵循以下代码.


The DataKeyNames is the same as of the primary key name of the dealer table.

And when you save the details to the database you can get the PK of the selected row in GridView automatically. To get the "DealerId" follow the code below in RowUpdating event.

protected void grdDealerDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
  int DealerId = Convert.ToInt32((grdDealerDetails.DataKeys[e.RowIndex]).Value.ToString());
        // Now you get the DealerId, do whatever you want with that.
}


这篇关于如何将网格视图特定的字段值以及一些值发送到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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