在C#一个gridview复杂的编辑 [英] Complex editing on a gridview in C#

查看:428
本文介绍了在C#一个gridview复杂的编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的考勤系统,具有以下表上:

I am working on an attendance system that has the following tables:

Entry
+---------+-----------+
+ EntryID + EntryDate +
+---------+ ----------+


Hour
+---------+--------+---------+
+ EntryID + InHour + OutHour +
+---------+--------+---------+

使用下面的示例数据

Entry
+---------+---------------------+
+ EntryID +     EntryDate       +
+---------+---------------------+
+   1     + 1/1/2010 8:00:00 AM +
+   2     + 1/1/2010 8:01:02 AM +
+---------+---------------------+

Hour
+---------+---------------------+-----------------------+
+ EntryID +        InHour       +        OutHour        +
+---------+---------------------+-----------------------+
+    1    + 1/1/2010 8:00:00 AM +  1/1/2010 1:00:00 PM  +
+    1    + 1/1/2010 2:04:00 PM +  1/1/2010 6:03:00 PM  +
+    2    + 1/1/2010 8:01:02 AM +  1/1/2010 1:02:00 PM  +
+---------+---------------------+-----------------------+

和我有以下的GridView:

And I have the following gridview:

我需要帮助,我应该如何处理一个请求我的客户端已经做到今天...

I need help with how I should approach a request my client has done today...

目前,调用此GridView中到达,当叶在字段通过查询数据库,并连接所有的时间在一个字符串,然后打印出来检索。然而,我的客户现在需要修改任何的时间在叶在列的能力。我不知道如何在所有接近这个请求,由于小时都在一个小区中分组在一起。我想过显示小时,一个textarea但有没有办法,这些变化将正确应用在数据库中,如果我这样做。

Currently, when calling this gridview the "Arrives At" and "Leaves At" fields are retrieved by querying the database and concatenating all the hours in a string then printing it out. However, my client now wants the ability to modify any of the hours in the "Leaves At" column. I don't know how to approach this request at all, since the hours are grouped together in one cell. I've thought showing the hours in a textarea but there's no way that the changes will be correctly applied on the database if I did this.

任何帮助将大大AP preciated,因为我觉得这个不堪重负。

Any help will be greatly appreciated as I feel overwhelmed by this.

在此先感谢,
伊顿公学B点。

Thanks in advance, Eton B.

推荐答案

一种方法是允许在一个更Ajaxy方式的更新,Aristos的讨论。这通常被认为是一种更人性化的做法,肯定会提供一个更好的用户体验,但需要熟悉jQuery和JavaScript和客户端和服务器之间的交互是稍微复杂一点,从您的角度来看。

One approach is to allow the updates in a more Ajaxy way, as Aristos discusses. This is typically considered a more user friendly approach and will certainly offer a nicer user experience, but requires familiarity with jQuery and JavaScript and the interactions between the client and the server are a little more complex from your perspective.

如果您希望继续使用Web控制范例,考虑将到达和叶在域模板列。在ItemTemplate你可以继续显示您连接的数据库中的文本,但你把一个GridView的EditItemTemplate里。这GridView控件可以绑定到数据源控件(也是在EditItemTemplate里),并配置支持编辑。如果你是编程方式绑定数据(也就是你的的使用数据源控件),那么你就需要将数据绑定到GridView的孩子每当父行变为可编辑。这可以通过声明标记,像这样做:

If you want to continue to use the Web control paradigm, consider making the "Arrives At" and "Leaves At" fields TemplateFields. In the ItemTemplate you could continue to display the text you concatenate at the database, but you'd put a GridView in the EditItemTemplate. This GridView could be bound to a data source control (also in the EditItemTemplate) and configured to support editing. If you are programmatically binding data (i.e., you are not using a data source control) then you'll need to bind the data to the child GridView whenever the parent row becomes editable. This can be done declaratively using markup like so:

<asp:TemplateField ...>
    <EditItemTemplate>
        <asp:GridView runat="server" id="gvChild" DataSource='<%# SomeFunction() %>' ...>
           ...
        </asp:GridView>
    </EditItemTemplate>
</asp:TemplateField>

在这里, SomeFunction 将是一个功能,在code-behind类(典型值),返回的数据绑定到网格。

Here, SomeFunction would be a function in your code-behind class (typically) that returns the data to bind to the grid.

另外,还可以通过父GridView的的RowDataBound 事件处理程序编程方式将数据绑定到孩子的GridView。也就是说,你会检查,看看你正在处理正在编辑的行(也就是说,如果 e.Row.RowIndex = ParentGridViewID.EditIndex )。如果是这样,你可以使用 e.Row.FindControl(ChildGridViewID)编程方式引用子GridView控件,然后设置其数据源属性并调用它的的DataBind 方法。

Alternatively, you could bind the data to the child GridView programmatically via the parent GridView's RowDataBound event handler. Namely, you would check to see if you are dealing with the row being edited (that is, if e.Row.RowIndex = ParentGridViewID.EditIndex). If so, you could programmatically reference the child GridView using e.Row.FindControl("ChildGridViewID") and then set its DataSource property and call its DataBind method.

当一个用户点击编辑按钮父电网到达和发表在细胞将显示为自己的编辑按钮修改个别次网格。或者,你可以把孩子的GridView编辑在ItemTemplate如果你想让用户编辑到达和发表在时代,而无需用户首先选择编辑父记录。

When a users clicks the Edit button for the parent grid the "Arrive At" and "Leave At" cells will show as a grid with Edit buttons of their own to modify the individual times. Alternatively, you could put the child editable GridView in the ItemTemplate if you wanted to let the users edit the "Arrive At" and "Leave At" times without requiring the user to first choose to edit the parent record.

这篇关于在C#一个gridview复杂的编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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