Hi all, I am using a datagrid and using Edit link command. I am suppose to take the new values on rowUpdating command and fire it to database. But I am getting only old values. I wrote an another page with little functionality, and it is working fine. I am anable to understand what is wrong with my code. I am posting the code below.
Partial Public Class ReferncePage Inherits System.Web.UI.Page Dim objBOReferedTable As BO.BOReferedTable Dim ObjControllerRelease As Controller.Manager Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles 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
End Class
my aspx class looks like this..
<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/HomeMaster.Master" CodeBehind="ReferncePage.aspx.vb" Inherits="UTM.ReferncePage" title=" Manage Reference Tables" %>
<%-- <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>--%>
<%--<asp:Button ID="Button1" runat="server" Style="left: 89px; position: relative; top: 344px"
Text="Button" />--%>
<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">
'>
<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>
Thanks and regards, Tanmay.