编程建立的GridView但回发时被称为更新点击prevents从RowUpdating [英] programatically creating GridView but postback when update clicked prevents RowUpdating from being called

查看:183
本文介绍了编程建立的GridView但回发时被称为更新点击prevents从RowUpdating的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是随便我希望有人能够给我一些指点的问题。我有这是一个编程根据设置的变量,从数据库中检索到的值相同aspx页面上的多个GridView的ASP页。

I'm just having an issue I'm hoping someone will be able to give me a few pointers. I have an asp page which is programatically creating multiple gridviews on the same aspx page depending on a variable set of values retrieved from the database.

由于我在编程code创建GridView的后面,我要创建GridView控件GridView的每次页面加载,回发,等OnInit的我目前页面OnInit函数中创建的GridView的。这一切工作正常,除了当用户进入行编辑模式,然后单击Update(行更新)按钮/链接。这迫使他们的价值观因而更新$ P $从不断推出pventing RowUpdating事件之前,从数据库,重新加载网格值网格中的回发。我该如何解决这个问题?我试图捕捉通过RowCommand事件选择的命令,但该事件仅得到回传后被解雇,所以OnInit函数被第一次调用之前Rowcommand所以我拍摄的命令名称是没有多大用处了我。

As I am programmatically creating the GridView in code behind, I have to create the gridview gridviews each time the page loads, on postback, oninit etc. I currently create the gridviews within the OnInit function of the page. This all works fine except for when the user goes into row edit mode then clicks the Update (row update) button/link. This forces a postback on the grid which reloads the grid values from database before their values are updated thus preventing the RowUpdating event from ever launching. How do I get around this? I have tried capturing the command selected via the RowCommand event but this event only gets fired after the postback, so the oninit function gets called first before the Rowcommand so the command name I've captured is of little use to me.

我创建GridView控件在OnInit函数如下

I am creating the GridView as follows in the Oninit function

    GridViewLineItem = New GridView
    If bEnableEdit = True Then
        GridViewLineItem.AutoGenerateEditButton = True
    End If

    If bEnableDelete = True Then
        GridViewLineItem.AutoGenerateDeleteButton = True
    End If

    GridViewLineItem.AutoGenerateColumns = False
    GridViewLineItem.EnableViewState = True
    GridViewLineItem.Font.Name = "Arial"
    GridViewLineItem.Font.Size = 8
    GridViewLineItem.ForeColor = Drawing.Color.Black
    GridViewLineItem.BackColor = Drawing.Color.White
    GridViewLineItem.BorderColor = Drawing.Color.LightGray
    GridViewLineItem.BorderStyle = BorderStyle.None
    GridViewLineItem.BorderWidth = 1
    GridViewLineItem.CellPadding = 4
    GridViewLineItem.AlternatingRowStyle.BackColor = Drawing.Color.White
    GridViewLineItem.FooterStyle.BackColor = Drawing.Color.BurlyWood
    GridViewLineItem.HeaderStyle.BackColor = Drawing.Color.DarkGray
    GridViewLineItem.HeaderStyle.Font.Bold = True
    GridViewLineItem.HeaderStyle.ForeColor = Drawing.Color.Black
    GridViewLineItem.PagerStyle.BackColor = Drawing.Color.Beige
    GridViewLineItem.PagerStyle.ForeColor = Drawing.Color.Black
    GridViewLineItem.PagerStyle.HorizontalAlign = HorizontalAlign.Right
    GridViewLineItem.RowStyle.BackColor = Drawing.Color.Beige
    GridViewLineItem.ID = "LineItemGridView" + strItemID

    strCBItemID = strItemID



    AddHandler GridViewLineItem.RowEditing, AddressOf GridViewLineItem_RowEditing
    AddHandler GridViewLineItem.RowCancelingEdit, AddressOf GridViewLineItem_RowCancelingEdit
    AddHandler GridViewLineItem.RowDataBound, AddressOf GridViewLineItem_RowDataBound
    AddHandler GridViewLineItem.RowUpdating, AddressOf GridViewLineItem_RowUpdating
    AddHandler GridViewLineItem.PageIndexChanging, AddressOf GridViewLineItem_PageIndexChanging
    AddHandler GridViewLineItem.PreRender, AddressOf GridViewLineItem_PreRender
    AddHandler GridViewLineItem.PageIndexChanged, AddressOf GridViewLineItem_PageIndexChanged
    AddHandler GridViewLineItem.RowDeleting, AddressOf GridViewLineItem_OnDeleting
    AddHandler GridViewLineItem.RowCommand, AddressOf GridViewLineItem_RowCommand



    'bind data source
    dt = New DataTable
    oda = New OleDb.OleDbDataAdapter
    oda.Fill(dt, rsGroup)
    GridViewLineItem.DataSource = dt
    GridViewLineItem.DataBind()

    'Add gridview to page    

    tCell.Controls.Add(GridViewLineItem)
    tRow.Cells.Add(tCell)
    TableLineItem.Rows.Add(tRow)


    LineItemPanel.Controls.Add(TableLineItem)
    LineItemPanel.BorderStyle = BorderStyle.Solid
    LineItemPanel.BorderWidth = 3
    LineItemPanel.BorderColor = Drawing.Color.DarkGray

    tGroupRow = New TableRow
    tGroupCell = New TableCell

    tGroupCell.ColumnSpan = TableGroupDetails.Rows.Item(0).Cells.Count
    tGroupCell.Controls.Add(LineItemPanel)

    tGroupRow.Cells.Add(tGroupCell)


    TableGroupDetails.Rows.Add(tGroupRow)

有人可以普莱舍给我当用户点击该行更新我应该怎么跳过GridView控件的数据绑定一些指点?我不能indisriminately配合GridView的数据绑定周围page.IsPostback =假,如果我这样做,该网格将只加载一次,另其他有效postsbacks当用户点击进入行编辑模式,比如会导致空网格。

Can someone plese give me some pointers in how I should skip the databind of the gridview when the user clicks on the row update? I can't tie the Gridview's Databind indisriminately around a page.IsPostback = false as if I do this, The grid will only be loaded once and another other valid postsbacks such as when the user clicks on to get into row edit mode would cause an empty grid.

感谢

太感谢了SomeGuy!移动GridView控件绑定到页。preRender解决了问题。我曾经被Page.Oninit事件(其中gridview的大干快上运行时创建的)的流量 - > Page.Load(GridView控件绑定) - > GridView.RowUpdating(我在那里commiting更改数据库)。现在是Page.OnInit(gridview的创造) - > GridView.RowUpdating(提交更改数据库) - >页面preRender(其中GridView控件被绑定)。唯一的问题现在虽然是我的渲染,通过了Itemplate GridView的编辑模式的ajaxcombobox。对于此,用户选择由时间GridView.RowUpdating事件被称为丢失。所有其他领域seuch为文本框保留用户的输入值。要深入到这个小有一点进一步看看我能找到。

Thanks a million SomeGuy! Moving the GridView bind to Page.PreRender resolved the issue. My flow of events used to be Page.Oninit (where gridview gets created on runtime) -> Page.Load (gridview bind) -> GridView.RowUpdating (where i was commiting the changes to database). It is now Page.OnInit (gridview creation) -> GridView.RowUpdating (committing change to database) -> Page.PreRender (where the gridview is being bound). Only Issue now though is I'm rendering an ajaxcombobox for the gridview's edit mode through iTemplate. The user selection for this is lost by the time GridView.RowUpdating event is called. All the other fields seuch as textboxes retain the user input value. Going to dig into this alittle further to see what I can find.

P.S。我不能发布这个作为下你的帖子出于某种原因...

P.S. I can't post this as a comment under your post for some reason...

P.P.S固定的问题与阿贾克斯组合框在GridView的编辑模式。只好将EnableViewState设置为true

P.P.S fixed issue with Ajax Combobox in gridview edit mode. had to set the enableviewstate to true

昏暗AjaxComb作为新AjaxControlToolkit.ComboBox

Dim AjaxComb As New AjaxControlToolkit.ComboBox

AjaxComb.EnableViewState = TRUE

AjaxComb.EnableViewState = True

这是小有一点奇怪的......你会觉得它的默认本来真的......

which is alittle weird... you'd think its default would have been true...

推荐答案

绑定在GridView的 Page.LoadComplete 页。preRender 事件,之后回发事件处理程序。您也可以尝试让GridView控件绑定本身的DataSourceID和一些DataSourceControl。

Bind the GridView on Page.LoadComplete or Page.PreRender events, after PostBack event handling routines. You can also try to let the GridView bind itself with DataSourceID and some DataSourceControl.

这篇关于编程建立的GridView但回发时被称为更新点击prevents从RowUpdating的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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