我正在使用数据网格并使用编辑链接命令。 我想在rowUpdating命令上获取新值并将其激发到数据库。但我只得到旧的价值观。 我写了另一个功能很少的页面,它运行正常。我能够理解我的代码有什么问题。我发布下面的代码。
部分公共课程参考页面 继承System.Web.UI.Page Dim objBOReferedTable作为BO.BOReferedTable Dim ObjControllerRelease As Controller.Manager 受保护的子Page_Load(ByVal sender As Object,ByVal e As System.EventArgs)处理Me.Load
If Page.IsPostBack = False Then
Try
FillTablesInDropDown()
BindData()
'ddl_TableName.SelectedIndex = 1
Catch ex As Exception
Common.AlertBox(ex.Message)
End Try
End If
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddl_TableName.SelectedIndexChanged
BindData()
DirectCast(Master.FindControl("lbl_PageHeader"), Label).Text = "Manage " + ddl_TableName.SelectedItem.Text.ToUpper + " Table"
End Sub
Private Sub dgv_RefTables_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles dgv_RefTables.RowCancelingEdit
dgv_RefTables.EditIndex = -1
BindData()
End Sub
Protected Sub dgv_RefTables_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles dgv_RefTables.RowCommand
Try
If e.CommandName.ToUpper = "ADD" Then
Dim txt_DispSeq As TextBox = DirectCast(dgv_RefTables.FooterRow.FindControl("_txtDispSeq"), TextBox)
Dim txt_Name As TextBox = DirectCast(dgv_RefTables.FooterRow.FindControl("_txtName"), TextBox)
Dim Chk_IsActive As CheckBox = DirectCast(dgv_RefTables.FooterRow.FindControl("_chkIsActive"), CheckBox)
objBOReferedTable = BO.BOReferedTable.getInstance
With objBOReferedTable
.Name = txt_Name.Text
.DisplaySequence = Convert.ToInt32(txt_DispSeq.Text)
.IsActive = Chk_IsActive.Checked
.AddedBy = CType(Session("UserProfile"), BOUserProfile).UserProfileId
.ChangedBy = .AddedBy
End With
Dim ctrl As New Controller.Manager
ctrl.AddToReferedTable(objBOReferedTable, ddl_TableName.SelectedValue)
End If
Catch ex As Exception
Common.AlertBox(ex.ToString)
End Try
BindData()
End Sub
Protected Sub dgv_RefTables_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles dgv_RefTables.RowEditing
dgv_RefTables.EditIndex = e.NewEditIndex
BindData()
End Sub
Private Sub dgv_RefTables_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles dgv_RefTables.RowUpdating
Dim row As GridViewRow
row = DirectCast(dgv_RefTables.Rows(e.RowIndex), GridViewRow)
Dim lbl As Label = CType(row.FindControl("lblID"), Label)
Dim txtDispSql As TextBox = CType(row.FindControl("txtDispSeq"), TextBox)
Dim txtName As TextBox = CType(row.FindControl("txtName"), TextBox)
Dim chkActive As CheckBox = CType(row.FindControl("chkIsActive"), CheckBox)
objBOReferedTable = BO.BOReferedTable.getInstance()
With objBOReferedTable
.AddedBy = CType(Session("UserProfile"), BOUserProfile).UserProfileId
.ChangedBy = .AddedBy
.DisplaySequence = Convert.ToInt32(txtDispSql.Text)
.Name = txtName.Text
.IsActive = chkActive.Checked
.ID = Convert.ToInt32(lbl.Text)
End With
Dim ctrl As New Controller.Manager
ctrl.UpdateReferedTableData(objBOReferedTable, ddl_TableName.SelectedValue)
' dgv_RefTables.EditIndex = -1
'BindData()
End Sub
Private Sub BindData()
Dim ctrl As New Controller.Manager
Dim dt As DataTable
dt = ctrl.SelectReferedTableData(ddl_TableName.SelectedValue)
If dt.Rows.Count = 0 Then
Dim BlankRow As DataRow
BlankRow = dt.NewRow
BlankRow.Item("IsActive") = False
dt.Rows.Add(BlankRow)
End If
If dt IsNot Nothing Then
dgv_RefTables.DataSource = dt
dgv_RefTables.DataBind()
End If
End Sub
Private Sub FillTablesInDropDown()
Dim Ctrl As New Controller.Manager
Dim dt As DataTable
dt = Ctrl.SelectAllReferenceTable()
ddl_TableName.DataSource = dt
ddl_TableName.DataTextField = "DisplayName"
ddl_TableName.DataValueField = "TableName"
ddl_TableName.DataBind()
End Sub
结束班
我的aspx类看起来像这样..
- %GT; - %GT; <asp:DropDownList ID="ddl_TableName" runat="server" AutoPostBack="true">
<%-- Style="left: 409px; position: relative;
top: -174px"AutoPostBack="True">--%>
</asp:DropDownList>
<asp:Panel ID="Panel1" runat="server" Height="308px" Style="position: relative; left: 0px; top: 0px;" Width="701px" ScrollBars="Auto">
<%--<table width="100%" border="0">
<tr>
<td align="center">
</td>
</tr>
<tr>
<td>
--%>
<asp:GridView ID="dgv_RefTables" runat="server"
AutoGenerateColumns="False"
DataKeyNames="ID"
ShowFooter="True"
OnRowCommand="dgv_RefTables_RowCommand" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" GridLines="None" Width="916px" AllowPaging="false" PageSize="5" CellSpacing="1">
“&GT;
<asp:TemplateField HeaderText="View Order"
SortExpression="DisplaySequence">
<ItemTemplate>
<asp:Label ID="lblDispSeq" runat="server"
Text='<%#Eval("DisplaySequence") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDispSeq" runat="server"
Text='<%#Bind("DisplaySequence") %>'>
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="_txtDispSeq" runat="server" >
</asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NAME"
SortExpression="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server"
Text='<%#Eval("Name") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtName" runat="server"
Text='<%#Bind("Name") %>'>
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="_txtName" runat="server">
</asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ACTIVE"
SortExpression="IsActive">
<ItemTemplate>
<asp:CheckBox ID="chk_IsActive" runat="server" Enabled="false" Text=""
Checked='<%#Eval("IsActive") %>'>
</asp:CheckBox>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="chkIsActive" runat="server"
Checked='<%#Bind("IsActive") %>'>
</asp:CheckBox>
</EditItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="_chkIsActive" runat="server">
</asp:CheckBox>
</FooterTemplate>
</asp:TemplateField>
谢谢和问候, Tanmay。
答案 0 :(得分:1)
尝试使用会话处理来填充回发过程的数据
答案 1 :(得分:0)
只需将Gridview的Enableviewstate属性设置为false即可获得新值
参考: http://www.codeproject.com/Questions/139076/not-getting-new-entered-values-on-grid-view-row-up (我得到了回答)