Solved

how do I handle a datagrid update using visual basic codebehind?

Posted on 2009-04-10
18
815 Views
Last Modified: 2013-11-15
hi experts,
in asp.net I have an aspx page (attached) constructed using Visual Studio visual tools which works just fine. I would like to do the same thing using codebehind.
So far I can edit, but no luck with the UPDATE.

my database table has four fields (Id,fld1,fld2,fld3)

the aspx page has the gridview thus:
<asp:GridView ID="GridView1" runat="server" />            
        </asp:GridView>

I have set AutoGenerateColumns=true

here is what I have so far :
Imports MySql
Imports MySql.Data
Imports MySql.Data.MySqlClient
Imports System.Data
Imports System.Web.Configuration

Partial Public Class page2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack = False Then
            BindGrid()
        End If
    End Sub

    Protected Sub BindGrid()
        Dim myConn As String = System.Configuration.ConfigurationManager.ConnectionStrings("tomsdb1ConnectionString").ConnectionString
        Dim myDataAdapter = New MySql.Data.MySqlClient.MySqlDataAdapter("SELECT * FROM tblone", myConn)
        Dim myBuilder As New MySqlClient.MySqlCommandBuilder(myDataAdapter)
        Dim showTable As New DataSet()
        myDataAdapter.Fill(showTable)
        GridView1.DataSource = showTable
        GridView1.Visible = True
        GridView1.DataBind()
    End Sub

    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
        BindGrid()
    End Sub

    Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
        GridView1.EditIndex = e.NewEditIndex
        BindGrid()
    End Sub

    Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
        GridView1.EditIndex = -1
        BindGrid()
    End Sub

    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim sql As String = "UPDATE tblone SET fld1=@fld1,fld2=@fld2,fld3=@fld3 WHERE Id=@Id"
        GridView1.EditIndex = -1
'....
        '' >>>> H E L P ??<<<<
'....
        GridView1.DataBind()
    End Sub
End Class
ASPX PAGE (works fine):
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            CellPadding="4" DataKeyNames="Id" DataSourceID="SqlDataSource1" 
            ForeColor="#333333" GridLines="None">
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" 
                    SortExpression="Id" />
                <asp:BoundField DataField="fld1" HeaderText="fld1" SortExpression="fld1" />
                <asp:BoundField DataField="fld2" HeaderText="fld2" SortExpression="fld2" />
                <asp:BoundField DataField="fld3" HeaderText="fld3" SortExpression="fld3" />
            </Columns>                  
        </asp:GridView>
        
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ProviderName="<%$ ConnectionStrings:tomsdb1ConnectionString.ProviderName %>" 
            ConnectionString="<%$ ConnectionStrings:tomsdb1ConnectionString %>" 
            DeleteCommand="DELETE FROM tblone WHERE (Id = @Id)" 
            InsertCommand="INSERT INTO tblone(fld1, fld2, fld3) VALUES (@fld1, @fld2, @fld)" 
            SelectCommand="SELECT tblone.* FROM tblone" 
            UpdateCommand="UPDATE tblone SET fld1 = @fld1, fld2 = @fld2, fld3 = @fld3 WHERE (Id = @Id)">
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>

Open in new window

0
Comment
Question by:tom_burkhardt
  • 10
  • 5
18 Comments
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 24118399
Hi,

Consider the following code:

Private sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrings("YourString").ConnectionString)

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim sql As String = "UPDATE tblone SET fld1=@fld1,fld2=@fld2,fld3=@fld3 WHERE Id=@Id"
        Dim updateCmd As New SqlCommand(sql, sqlConn)
        sqlConn.Open()
        updateCmd.ExecuteNonQuery()
        sqlConn.Close()
        GridView1.DataBind()
        e.Cancel = True
        GridView1.EditIndex = -1
        GridView1.DataBind()
    End Sub

You also need to add eventhandler for the GridView1_RowCancelingUpdate event. I don't have access to my dev box for the moment, all code written on the fly so there might be errors.

/Carl.
0
 

Author Comment

by:tom_burkhardt
ID: 24118617
@carlnorrbom,
I run that, do an edit - and when I hit "update" the browser screen goes blank. No change to the database.

And for the GridView1_RowCancelingUpdate, does it need more than what I already showed you above?
0
 

Author Comment

by:tom_burkhardt
ID: 24118786

just noticed  you'd said
GridView1_RowCancelingUpdate,
not
GridView1_RowCancelingEdit
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:tom_burkhardt
ID: 24118822
(should point out I'm still a newbie) ...

do I need to declare my parameters somewhere, or are they picked up automatically?
0
 

Author Comment

by:tom_burkhardt
ID: 24120006
the reason I'm asking about declaring parameters is that I believe a datagrid will not display if there are no values reaching it from the data source.
0
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 24131145
Hi,

Yes You need to declare the parameters, i.e:

updateCmd.Parameters.AddWithValue("@fld1", YourParameterInputHere)
updateCmd.Parameters.AddWithValue("@fld2", SecondInput..)
...

/Carl.
0
 

Author Comment

by:tom_burkhardt
ID: 24132230
@carlnorrbom:
over the weekend I did try that, with the same result, the edit fields came up for each row, and let me add/change text, but when clicked "update" the web page went blank, and there was no change to the database.

the update codebehind, as you suggested , looks like:
    Private sqlConn As New MySqlClient.MySqlConnection(ConfigurationManager.ConnectionStrings("tomsdb1ConnectionString").ConnectionString)
    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim sql As String = "UPDATE tblone SET fld1=@fld1,fld2=@fld2,fld3=@fld3 WHERE Id=@Id"
        Dim updateCmd As New MySqlCommand(sql, sqlConn)
        updateCmd.Parameters.AddWithValue("@Id", MySqlDbType.Int32)
        updateCmd.Parameters.AddWithValue("@fld1", MySqlDbType.VarChar)
        updateCmd.Parameters.AddWithValue("@fld2", MySqlDbType.VarChar)
        updateCmd.Parameters.AddWithValue("@fld3", MySqlDbType.VarChar)
        sqlConn.Open()
        updateCmd.ExecuteNonQuery()
        sqlConn.Close()
        e.Cancel = True
        GridView1.EditIndex = -1
        GridView1.DataBind()
        GridView1.Visible = True
    End Sub

I also tried

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim prmGridView0, prmGridView1, prmGridView2, prmGridView3 As MySqlParameter
        Dim sql As String = "UPDATE tblone SET fld1=@fld1,fld2=@fld2,fld3=@fld3 WHERE Id=@Id"
        Dim updateCmd As New MySqlCommand(sql, sqlConn)
        prmGridView0 = updateCmd.Parameters.Add(New MySqlParameter("@Id", MySqlDbType.Int32))
        prmGridView1 = updateCmd.Parameters.Add(New MySqlParameter("@fld1", MySqlDbType.VarChar))
        prmGridView2 = updateCmd.Parameters.Add(New MySqlParameter("@fld2", MySqlDbType.VarChar))
        prmGridView3 = updateCmd.Parameters.Add(New MySqlParameter("@fld3", MySqlDbType.VarChar))
        prmGridView0.Value = ViewState("Id")
        prmGridView1.Value = ViewState("fld1")
        prmGridView2.Value = ViewState("fld2")
        prmGridView3.Value = ViewState("fld3")
        sqlConn.Open()
        updateCmd.ExecuteNonQuery()
        sqlConn.Close()
        e.Cancel = True
        GridView1.EditIndex = -1
        GridView1.DataBind()
        GridView1.Visible = True
    End Sub

I must be doing something wrong somewhere. It cannot be the connection string, since the datagrid fills nicely on PageLoad().
0
 

Author Comment

by:tom_burkhardt
ID: 24132353
for what it's worth, when I click on "edit" for a row and then hover the mouse over "update" and "cancel", I can see javascript code in the status line at the bottom of the Browser.

for the first row hovering over "update" gives me
javascript:_doPostBack('GridView1$ctl02$ctl00','')
and hovering over "cancel" gives me
javascript:_doPostBack('GridView1','Cancel$0')

for the second row  hovering over "update" gives me
javascript:_doPostBack('GridView1$ctl03$ctl00','')
and hovering over "cancel" gives me
javascript:_doPostBack('GridView1','Cancel$1')

and so on...
do I have to include some sort of findControl statement somewhere??  asked the newbie.
0
 

Author Comment

by:tom_burkhardt
ID: 24140923
help? anybody??
0
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 24146658
Hi,

Sorry for not responding but I have been traveling at work. Anyways, please find attached some example code on how to do this. In this example I have a database table containing 4 fields (ID, FirstName, LastName, Company) which I bind dynamically to a gridview using a datatable. The updating is managed programatically. Please note the usage of DataKeys(i) and that "ID" is specified as DataKeyName declaratively in the markup for the GridView. Hope this helps.

/Carl.
GridViewPage.aspx:
 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="GridViewPage.aspx.vb" Inherits="GridViewPage" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" 
            CellPadding="4" ForeColor="#333333" GridLines="None">
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:CommandField CausesValidation="False" ShowEditButton="True" />
                <asp:BoundField DataField="ID" HeaderText="ID:" SortExpression="ID" 
                    Visible="True" />
                <asp:TemplateField HeaderText="First Name:" SortExpression="FirstName">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Last Name:" SortExpression="LastName">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtLastName" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Company:" SortExpression="Company">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtCompany" runat="server" Text='<%# Bind("Company") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("Company") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
    </div>
    </form>
</body>
</html>
 
GridViewPage.aspx.vb:
 
Imports System.Data
Imports System.Data.SqlClient
 
Partial Class GridViewPage
    Inherits System.Web.UI.Page
 
    Private dbConn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            BindGrid(GridView1)
        End If
    End Sub
 
    Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
        GridView1.EditIndex = e.NewEditIndex
        BindGrid(GridView1)
        GridView1.Rows(e.NewEditIndex).Cells(1).Enabled = False 'Protect ID Column
    End Sub
 
    Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
        GridView1.EditIndex = -1
        BindGrid(GridView1)
    End Sub
 
    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim strUpdateCustomers As String = "UPDATE Customers SET FirstName = @FirstName, LastName = @LastName, Company = @Company WHERE (ID = @ID)"
        Dim cmdUpdateCustomers As New SqlCommand(strUpdateCustomers, dbConn)
 
        cmdUpdateCustomers.Parameters.AddWithValue("@ID", GridView1.DataKeys(e.RowIndex).Values(0))
        cmdUpdateCustomers.Parameters.AddWithValue("@FirstName", CType(GridView1.Rows(e.RowIndex).FindControl("txtFirstName"), TextBox).Text)
        cmdUpdateCustomers.Parameters.AddWithValue("@LastName", CType(GridView1.Rows(e.RowIndex).FindControl("txtLastName"), TextBox).Text)
        cmdUpdateCustomers.Parameters.AddWithValue("@Company", CType(GridView1.Rows(e.RowIndex).FindControl("txtCompany"), TextBox).Text)
 
        Try
            If Not dbConn.State = ConnectionState.Open Then
                dbConn.Open()
            End If
            cmdUpdateCustomers.ExecuteNonQuery()
        Catch ex As Exception
            'Logic to handle exception
        End Try
        If Not dbConn.State = ConnectionState.Closed Then
            dbConn.Close()
        End If
        e.Cancel = True
        GridView1.EditIndex = -1
        BindGrid(GridView1)
    End Sub
 
    Private Sub BindGrid(ByVal gv As GridView)
        Dim strSelectCustomers As String = "SELECT * FROM Customers ORDER BY LastName"
        Dim cmdSelectCustomers As New SqlDataAdapter(strSelectCustomers, dbConn)
        Dim dtCustomers As New DataTable()
        cmdSelectCustomers.Fill(dtCustomers)
        gv.DataSource = dtCustomers.DefaultView()
        gv.DataBind()
    End Sub
 
End Class

Open in new window

0
 

Author Comment

by:tom_burkhardt
ID: 24149030
hi Carl, thanks for getting back to me.

Your code gave me some progress, in that the web page no longer blanks, and there is an attempt to run through code.

However, I now get an error message when the attempt is made to add the "fld1" parameter.
the message is :
"NullReference Exception was undhandled by user code:
Object reference not set to an instance of an object."

I tried using
updateCmd.Parameters.AddWithValue(New MySqlParameter("@fld1", CType(GridView1.Rows(e.RowIndex).FindControl("fld1"), TextBox).Text))

and was told:
value of type MySQLParameter cannot be converted to 'String'

then I tried using
updateCmd.Parameters.Add(New MySqlParameter("@fld1", CType(GridView1.Rows(e.RowIndex).FindControl("fld1"), TextBox).Text))

and once again got:
"NullReference Exception was undhandled by user code:
Object reference not set to an instance of an object."

Sorry, as a newbie that's as far as I could figure out to try.
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" 
            CellPadding="4" ForeColor="#333333" GridLines="None">
            <RowStyle BackColor="#EFF3FB" />
 
           <Columns> 
               <asp:CommandField CausesValidation="False" ShowEditButton="True" /> 
               <asp:BoundField DataField="Id" HeaderText="Id:" SortExpression="Id" Visible="True" />
 
               <asp:TemplateField HeaderText="fld1:" SortExpression="fld1">
                    <EditItemTemplate>
                        <asp:TextBox Id="txtfld1" runat="server" Text='<%# Bind("fld1") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label Id="Label1" runat="server" Text='<%# Bind("fld1") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
 
                <asp:TemplateField HeaderText="Last Name:" SortExpression="fld2">
                    <EditItemTemplate>
                        <asp:TextBox Id="txtfld2" runat="server" Text='<%# Bind("fld2") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label Id="Label2" runat="server" Text='<%# Bind("fld2") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
 
               <asp:TemplateField HeaderText="fld3:" SortExpression="fld3">
                    <EditItemTemplate>
                        <asp:TextBox Id="txtfld3" runat="server" Text='<%# Bind("fld3") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label Id="Label3" runat="server" Text='<%# Bind("fld3") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField> 
           </Columns>
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
    </div>
    </form>
</body>
 
 
Imports MySql.Data
Imports MySql.Data.MySqlClient
Imports System.Data
 
Partial Public Class page2
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack = False Then
            BindGrid(GridView1)
        End If
    End Sub
 
    Protected Sub BindGrid(ByVal gv As GridView)
        Dim myConn As String = System.Configuration.ConfigurationManager.ConnectionStrings("tomsdb1ConnectionString").ConnectionString
        Dim myDataAdapter = New MySql.Data.MySqlClient.MySqlDataAdapter("SELECT * FROM tblone", myConn)
        Dim myBuilder As New MySqlClient.MySqlCommandBuilder(myDataAdapter)
        Dim showTable As New DataSet()
        myDataAdapter.Fill(showTable)
        gv.DataSource = showTable
        gv.Visible = True
        gv.DataBind()
    End Sub
 
    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
        BindGrid(GridView1)
    End Sub
 
    Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
        GridView1.EditIndex = e.NewEditIndex
        BindGrid(GridView1)
    End Sub
 
    Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
        GridView1.EditIndex = -1
        BindGrid(GridView1)
    End Sub
 
    Private sqlConn As New MySqlClient.MySqlConnection(ConfigurationManager.ConnectionStrings("tomsdb1ConnectionString").ConnectionString)
    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim strUpdate As String = "UPDATE tblone SET fld1=@fld1,fld2=@fld2,fld3=@fld3 WHERE (Id=@Id)"
        Dim updateCmd As New MySqlCommand(strUpdate, sqlConn)
        updateCmd.Parameters.AddWithValue("@Id", GridView1.DataKeys(e.RowIndex).Values(0))
        updateCmd.Parameters.AddWithValue("@fld1", CType(GridView1.Rows(e.RowIndex).FindControl("fld1"), TextBox).Text)
        updateCmd.Parameters.AddWithValue("@fld2", CType(GridView1.Rows(e.RowIndex).FindControl("fld2"), TextBox).Text)
        updateCmd.Parameters.AddWithValue("@fld3", CType(GridView1.Rows(e.RowIndex).FindControl("fld3"), TextBox).Text)
 
        Try
            If Not sqlConn.State = ConnectionState.Open Then
                sqlConn.Open()
            End If
            updateCmd.ExecuteNonQuery()
        Catch ex As Exception
            '
        End Try
        If Not sqlConn.State = ConnectionState.Closed Then
            sqlConn.Close()
        End If
        e.Cancel = True
        GridView1.EditIndex = -1
        BindGrid(GridView1)
    End Sub
End Class

Open in new window

0
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 500 total points
ID: 24174220
Hi,

From what I can see Your server control ID's does not match between markup and code behind, for instance:

    <EditItemTemplate>
        <asp:TextBox Id="txtfld1" runat="server" Text='<%# Bind("fld1") %>'></asp:TextBox>
    </EditItemTemplate>


    updateCmd.Parameters.AddWithValue("@fld1", CType(GridView1.Rows(e.RowIndex).FindControl("fld1"), TextBox).Text)

The parameter lines in code behind should read:

    updateCmd.Parameters.AddWithValue("@fld1", CType(GridView1.Rows(e.RowIndex).FindControl("txtfld1"), TextBox).Text)
    updateCmd.Parameters.AddWithValue("@fld1", CType(GridView1.Rows(e.RowIndex).FindControl("txtfld2"), TextBox).Text)
    updateCmd.Parameters.AddWithValue("@fld1", CType(GridView1.Rows(e.RowIndex).FindControl("txtfld3"), TextBox).Text)

It is the text property of the textbox you should supply as parameter, not the "field value". Hope this helps.

/Carl.
0
 

Author Comment

by:tom_burkhardt
ID: 24175367
eighteen thumbs up!!

thank you Carl, that was indeed the problem. Cannot thank you enough for your patience and help. If nothing else, you have saved my sanity.

As I said in my initial question, the ASPX page is easy enough to create simply using the Visual toolbox and dragging icons onto the blank template. However I am old school and need to know what is going on under the hood. Also I need as much as possible to separate design from function so that the graphic designers I work with can do their thing on the page without any fear of messing up the code part.

Thank you again!
0
 

Author Closing Comment

by:tom_burkhardt
ID: 31569005
thank you so much for your help. You have given a newbie the motivation to keep going in a fairly complex environment (codebehind).
0
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 24175630
tom_burkhardt,

You're more than welcome and thx for your feedback. I agree declarative markup should be left to designers. I strive to keep as much as possible of my application and business logic separated from the UI and also to the farthest extent possible break out business logic and data access logic into separate classes. This approach highly increases your productivity and allows for much easier application maintenance and decreases errors.

For instance, breaking out widely / commonly used code into a class library and compiling it into it's own dll makes it very easy to just add as a reference to your next project and reuse all the functions and methods without writing a single line of code!

Good luck with your future projects and don't hesitate coming back to EE if you have future questions! You won't learn if you don't try!

/Carl.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
performance issue in asp web 5 33
jquery datatables, asp.net MVC 9 41
REXEX help Part 2 2 25
Downside of adding characters set in ASP pages 6 22
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question