编写完全动态的Gridview [英] Coding a Completely Dynamic Gridview

查看:64
本文介绍了编写完全动态的Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来正确设置我的事件.这是怎么回事.

我有一个项目,在用户选择某些选项之前,我不知道GridView的数量或位置.我需要在一个ASP页面上完成所有操作.

我发现可以动态创建并填充GridView并将其添加到占位符的控件中.

I need help getting my events set up correctly. Here''s what''s going on.

I have a project where I don''t know the number or location of GridViews until the user selects some options. I need to do this all on one asp page.

I have figured out that I can create and populate a GridView dynamically and add it to a placeholder''s controls.

<asp:PlaceHolder ID="phTimeEntryDay" runat="server"></asp:PlaceHolder>


Protected WithEvents gvTimeEntry As GridView = New GridView()
phTimeEntryDay.Controls.Add(gvTimeEntry)


我已经使用代码添加了edit和delete命令:


I have added the edit and delete commands using code:

Dim cColumn As New CommandField

cColumn.ButtonType = ButtonType.Link
cColumn.CancelText = "Cancel"
cColumn.UpdateText = "Update"
cColumn.EditText = "Edit"
cColumn.DeleteText = "Delete"
cColumn.ShowEditButton = True
cColumn.ShowDeleteButton = True
cColumn.ShowCancelButton = True

gvTimeEntry.Columns.Add(cColumn)


这确实设置了正确的回发javascript事件,但是当我单击链接并将页面发回时,什么也没有发生.

在另一个我在设计时创建了gridview的项目中,我找不到为处理事件而创建的任何代码,这些事件可以复制到我在运行时执行所有操作的项目中.


This does set up the correct postback javascript events, but nothing happens when I click the links and the page is posted back.

In another project where I created the gridview at design-time, I can''t find any code created to handle the events that I can copy to my project that does everything at run-time.

<asp:GridView ID="GridViewTimeSheet" runat="server" AllowSorting="True" AutoGenerateColumns="False"

    DataKeyNames="EmpPerNo,FromDate,ToDate,EntrySequence" DataSourceID="SqlDataSourcetimeEntry"

    ShowFooter="True" EmptyDataText="No Data Available.">
    <Columns>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
...


我发现的唯一完整示例是在C#中使用DataGrid而不是GridView,并且DataGrid和GridView有足够的差异,我无法完全适应它.

如果有的话,可以使用VB或C#中的示例.

任何帮助将不胜感激.

谢谢,
Bryan Lee


The only complete example I''ve found uses DataGrid in C# instead of GridView and there are enough differences in DataGrid and GridView that I can''t adapt it completely.

Examples in VB or C# are fine if you have some.

Any help would be greatly appreciated.

Thanks,
Bryan Lee

推荐答案

我在msdn上找到了此参考,它为我提供了我需要处理的事件以及如何处理它们的示例.

http://msdn.microsoft .com/en-us/library/system.web.ui.webcontrols.gridview.rowediting(v = vs.90).aspx [
I found this reference at msdn that gives me examples of the events I need to handle and how to handle them.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowediting(v=vs.90).aspx[^]

Thank you, Aidin, for jogging my brain.


这篇关于编写完全动态的Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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