Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Updating Via A Datagrid Woes


Message #1 by "Phil McAllister" <PhilMc@8...> on Wed, 29 May 2002 10:18:07 -0700
Chuck,

That's great! Please send me too at jimitron@i...

Thanks,

Jimi

----- Original Message -----
From: "Feduke Cntr Charles R" <FedukeCR@m...>
To: "ASPX_Professional" <aspx_professional@p...>
Sent: Thursday, May 30, 2002 12:37 AM
Subject: [aspx_professional] RE: Updating Via A Datagrid Woes


> Phil,
>
> I'm going to send you my Grid.cs and DataGrid.cs files in a seperate
> e-mail.  The DataGrid does a rather lightweight implementation of what
> you're trying to do, sans the automatic creation based off of a SELECT
> query.  I know it was a pain to get my current implementations to where
they
> are now, and I think you might be able to make use of the code as an
example
> (or even inherit from CreativeTechnology.Web.UI.DataGrid for your grid!).
>
> FYI if you have a SQL INSERT or UPDATE statement, there's really no
> reason to use a DataAdapter to make the save.  Just execute the command!
> Also, you might want to consider:
>
> string sql = String.Format("INSERT INTO {0} (last, first, age)" +
> " VALUES ('{1}', '{2}', {3})",
> "tblPeople",
> txtLast.Value,
> txtFirst.Value,
> txtAge.Value);
>
> as that creates a very clean, readable SQL statement.
>
> If anyone else would like the source code for custom Grid and
> DataGrid controls, let me know.
>
> Example implementation:
> ---
> <%@ Register TagPrefix="Ex"
> Namespace="CreativeTechnology.Web.UI.WebControls"
> Assembly="Ex" %>
> <Ex:DataGrid id="grid" AllowAddNew="true"
> OnDeleteCommand="DeleteCommand"
> OnUpdateCommand="UpdateCommand"
> ProcessSqlCommand="false" ShowFooter="true" ShowHeader="true"
> SqlSelect="SELECT * FROM tblPeople ORDER BY last"
> AutoGenerateColumns="false"
> CssClass="datagrid" RunAt="server">
> <!-- your templates here -->
> </Ex:DataGrid>
> ---
> // protected controls
> protected CreativeTechnology.Web.UI.WebControls.DataGrid grid;
> // in void Page_Load
> grid.DataBind();
> ---
>
> HTH,
> - Chuck
>
> -----Original Message-----
> From: Phil McAllister [mailto:PhilMc@8...]
> Sent: Wednesday, May 29, 2002 1:18 PM
> To: ASPX_Professional
> Subject: [aspx_professional] Updating Via A Datagrid Woes
>
>
> PLEASE HELP ME!!!  I have a two-fold problem.  First off, I am unable to
> capture the updated value when I click "Update".  The original value is
what
> is contained in e.Item.Cells(2).Controls(0).  This is quite perplexing
> because no matter what value I update the cell with, nothing changes . . .
I
> continue to be returned the original value.  Also, the reason I am using
> e.Item.Cells(2).Controls(0) if Visual Studio .NET is because the
application
> I am building is a utility that dynamically builds the datagrid based on a
> query.
>
> OK, here is the second half of my problem.  I do not know what to use to
> actually update my database.  No matter what I try, the database data
stays
> the same.  Here is the UpdateCommand subroutine that I am developing:
>
> ***********************************************************
>     Private Sub datNames_UpdateCommand(ByVal source As Object, ByVal e As
> System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
> datNames.UpdateCommand
>         Dim TextBox2 As TextBox
>         Dim strVar2 As String
>         Dim TextBox3 As TextBox
>         Dim strVar3 As String
>         Dim da As New SqlClient.SqlDataAdapter()
>         Dim strSQL As String
>
>         TextBox2 = e.Item.Cells(2).Controls(0)
>         strVar2 = TextBox2.Text
>
>         TextBox3 = e.Item.Cells(3).Controls(0)
>         strVar3 = TextBox3.Text
>
>         strSQL = "UPDATE " & Cache("Table_Name") & _
>         " SET " & _
>         "( " & ds.Tables(0).Columns(1).ColumnName() & _
>         " = '" & strVar2 & "')" & _
>         " AND ( " & ds.Tables(0).Columns(2).ColumnName() & _
>         " = '" & strVar3 & "')" & _
>         " WHERE ID = " & datNames.DataKeys(e.Item.ItemIndex)
>
>         da = New SqlClient.SqlDataAdapter(strSQL, _
>             Application("ConnectString").ToString)
>
>         da.Update(ds)
>         datNames.EditItemIndex = -1
>         datNames.DataBind()
>     End Sub
> End Class
> ***********************************************************
>
> By the way, the SQL statement that is created from the variables and
> concatenations above, is exactly the one that I desire (except for the
> e.Item.Cells(?).Controls(0) controls holding the original values from the
> query . . . not the current values that I just typed in).  Also, the
dataset
> (ds) is declared globally and was populated originally with a simple
> "SELECT" query.  Thank you.
>
> PLEASE HELP ME,
>
> Phil
>
>
>
>


  Return to Index