R
rn5a
A Form has a DataGrid which displays records from a SQL Server 2005 DB
table. Users can modify the records using this DataGrid for which I am
using EditCommandColumn in the DataGrid. This is the code:
<script runat="server">
Dim sqlConn As New SqlConnection(".....")
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
FillDataGrid()
End If
End Sub
Sub EditData(ByVal obj As Object, ByVal ea As
DataGridCommandEventArgs)
FillDataGrid(ea.Item.ItemIndex)
End
Sub FillDataGrid(Optional ByVal EditIndex As Integer = -1)
Dim dSet As DataSet
Dim sqlDapter As SqlDataAdapter
sqlDapter = New SqlDataAdapter("SELECT * FROM Users", sqlConn)
Response.Write("EditIndex: " & EditIndex & "<br>")
dSet = New DataSet
sqlDapter.Fill(dSet)
dgUsers.DataSource = dSet
dgUsers.DataBind()
End Sub
</script>
<form runat="server">
<aspataGrid ID="dgUsers" OnEditCommand="EditData" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="UserName">
<ItemTemplate>
<asp:Label ID="lblUserName" runat="server"><%#
Container.DataItem("UserName") %></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="FirstName" HeaderText="First Name"/>
<asp:BoundColumn DataField="LastName" HeaderText="Last Name"/>
<asp:BoundColumn DataField="Address" HeaderText="Address"/>
<asp:EditCommandColumn CancelText="CANCEL" EditText="EDIT"
HeaderText="Edit" UpdateText="UPDATE"/>
<asp:ButtonColumn CommandName="Delete" HeaderText="Delete"
Text="DELETE"/>
</Columns>
</aspataGrid>
</form>
Now when the page loads for the first time, as expected, the DataGrid
displays all the records with each row accompanied by the "Edit" link.
But when the "Edit" link of any of the rows is clicked, the
BoundColumns (i.e. FirstName, LastName & Address) do not change to
TextBoxes.
What am I doing wrong here?
table. Users can modify the records using this DataGrid for which I am
using EditCommandColumn in the DataGrid. This is the code:
<script runat="server">
Dim sqlConn As New SqlConnection(".....")
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
FillDataGrid()
End If
End Sub
Sub EditData(ByVal obj As Object, ByVal ea As
DataGridCommandEventArgs)
FillDataGrid(ea.Item.ItemIndex)
End
Sub FillDataGrid(Optional ByVal EditIndex As Integer = -1)
Dim dSet As DataSet
Dim sqlDapter As SqlDataAdapter
sqlDapter = New SqlDataAdapter("SELECT * FROM Users", sqlConn)
Response.Write("EditIndex: " & EditIndex & "<br>")
dSet = New DataSet
sqlDapter.Fill(dSet)
dgUsers.DataSource = dSet
dgUsers.DataBind()
End Sub
</script>
<form runat="server">
<aspataGrid ID="dgUsers" OnEditCommand="EditData" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="UserName">
<ItemTemplate>
<asp:Label ID="lblUserName" runat="server"><%#
Container.DataItem("UserName") %></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="FirstName" HeaderText="First Name"/>
<asp:BoundColumn DataField="LastName" HeaderText="Last Name"/>
<asp:BoundColumn DataField="Address" HeaderText="Address"/>
<asp:EditCommandColumn CancelText="CANCEL" EditText="EDIT"
HeaderText="Edit" UpdateText="UPDATE"/>
<asp:ButtonColumn CommandName="Delete" HeaderText="Delete"
Text="DELETE"/>
</Columns>
</aspataGrid>
</form>
Now when the page loads for the first time, as expected, the DataGrid
displays all the records with each row accompanied by the "Edit" link.
But when the "Edit" link of any of the rows is clicked, the
BoundColumns (i.e. FirstName, LastName & Address) do not change to
TextBoxes.
What am I doing wrong here?