Yes I have all that too.

The thing is that I'm using a search form with
textboxes where user enters in lastname/firstname,
then those 2 parameters are passed to the select,
edit, and update sub routines. Everything works fine,
but after the first update, the values in the
textboxes of my search forms remains even after the
datagrid gets rebinded after update. Without touching
the textboxes, if the user decides to EDIT again (2nd
time), the datagrid does not return the record, thus
empty datagrid because the old values from the
lastname/firstname textboxes are being passed.

I mean it's probably a slim chance that the user would
forget something and click EDIT again after the
update, but I would like to know to resolve that.

Here's my code:

===================================================
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data.Oledb" %>
<%@ import Namespace="System.Data" %>
<script runat="server">

    Function GetCoordinator(ByVal lastName As String,
ByVal firstName As String) As System.Data.IDataReader
            Dim connectionString As String = ""
            Dim dbConnection As
System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
    
            Dim queryString As String = "SELECT
[Coordinator].* FROM [Coordinator] WHERE
(([Coordinator].[LastName] = @Las"& _
    "tName) AND ([Coordinator].[FirstName] =
@FirstName))"
            Dim dbCommand As System.Data.IDbCommand =
New System.Data.SqlClient.SqlCommand
            dbCommand.CommandText = queryString
            dbCommand.Connection = dbConnection
    
            Dim dbParam_lastName As
System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
            dbParam_lastName.ParameterName =
"@LastName"
            dbParam_lastName.Value = lastName
            dbParam_lastName.DbType =
System.Data.DbType.StringFixedLength
            dbCommand.Parameters.Add(dbParam_lastName)
            Dim dbParam_firstName As
System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
            dbParam_firstName.ParameterName =
"@FirstName"
            dbParam_firstName.Value = firstName
            dbParam_firstName.DbType =
System.Data.DbType.StringFixedLength
           
dbCommand.Parameters.Add(dbParam_firstName)
    
            dbConnection.Open
            Dim dataReader As System.Data.IDataReader
=
dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    
            Return dataReader
        End Function
    
    
    
    Sub Button1_Click(sender As Object, e As
EventArgs)
    
            dgCoordinator.DataSource =
GetCoordinator(lname.Text, fname.Text)
            dgCoordinator.DataBind()
    
            If dgCoordinator.Items.Count = 0 then
                dgCoordinator.Visible = False
                Label2.Text = "No record found. Please
try again."
    
            End If
    
    
    End Sub
    
    
    Sub dgCoordinator_Edit(sender as Object, e as
DataGridCommandEventArgs)
        dgCoordinator.EditItemIndex = e.Item.ItemIndex
    
        dgCoordinator.DataSource =
GetCoordinator(lname.Text, fname.Text)
        dgCoordinator.DataBind()
    End Sub
    
    
    Sub dgCoordinator_Update(sender as Object, e as
DataGridCommandEventArgs)
        'update database
        'determine the value of the coordinator id
column
        Dim userID as Integer = e.Item.Cells(1).Text
    
        'reference each textbox
        Dim uname as TextBox =
e.Item.Cells(2).Controls(0)
        Dim pword as TextBox =
e.Item.Cells(3).Controls(0)
        Dim lname as TextBox =
e.Item.Cells(4).Controls(0)
        Dim fname as TextBox =
e.Item.Cells(5).Controls(0)
        Dim email as TextBox =
e.Item.Cells(6).Controls(0)
        Dim phone as TextBox =
e.Item.Cells(7).Controls(0)
        Dim regcode as TextBox =
e.Item.Cells(8).Controls(0)
    
        UpdateCoordinator(userID, uname.Text,
pword.Text, lname.Text, fname.Text, email.Text,
phone.Text, regcode.Text)
    
        dgCoordinator.EditItemIndex = -1
    
    
        dgCoordinator.DataSource =
GetCoordinator(lname.Text, fname.Text)
        dgCoordinator.DataBind()
    
        Label1.Text = "Record has been updated."
    
     End Sub
    
    
    Sub dgCoordinator_Cancel(sender as Object, e as
DataGridCommandEventArgs)
        dgCoordinator.EditItemIndex = -1
    
        dgCoordinator.DataSource =
GetCoordinator(lname.Text, fname.Text)
        dgCoordinator.DataBind()
    End Sub
    
    
    
        Function UpdateCoordinator(ByVal userID As
Integer, ByVal uname As String, ByVal pword As String,
ByVal lName As String, ByVal fName As String, ByVal
email As String, ByVal phone As String, ByVal regcode
As String) As Integer
            Dim connectionString As String = ""
            Dim sqlConnection As
System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
    
            Dim queryString As String = "UPDATE
[Coordinator] SET [EMAIL PROTECTED],
[EMAIL PROTECTED], [EMAIL PROTECTED],
[EMAIL PROTECTED], [EMAIL PROTECTED],
[EMAIL PROTECTED], [EMAIL PROTECTED] WHERE ([C"& _
    "oordinator].[UserUID] = @UserUID)"
            Dim sqlCommand As
System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString,
sqlConnection)
    
            sqlCommand.Parameters.Add("@UserUID",
System.Data.SqlDbType.Int).Value = userID
            sqlCommand.Parameters.Add("@Username",
System.Data.SqlDbType.VarChar).Value = uname
            sqlCommand.Parameters.Add("@Password",
System.Data.SqlDbType.VarChar).Value = pword
            sqlCommand.Parameters.Add("@LastName",
System.Data.SqlDbType.VarChar).Value = lname
    
            sqlCommand.Parameters.Add("@FirstName",
System.Data.SqlDbType.VarChar).Value = fname
            sqlCommand.Parameters.Add("@Email",
System.Data.SqlDbType.VarChar).Value = email
            sqlCommand.Parameters.Add("@Phone",
System.Data.SqlDbType.VarChar).Value = phone
            sqlCommand.Parameters.Add("@Region",
System.Data.SqlDbType.VarChar).Value = regcode
    
            Dim rowsAffected As Integer = 0
            sqlConnection.Open
            Try
                rowsAffected =
sqlCommand.ExecuteNonQuery
            Finally
                sqlConnection.Close
            End Try
    
            Return rowsAffected
        End Function
    
    
    Sub Button2_Click(sender As Object, e As
EventArgs)
         Dim myForm As Control =
Page.FindControl("form1")
         Dim ctl As Control
         For Each ctl In myForm.Controls
            If
ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox")
Then
               CType(ctl, TextBox).Text = ""
            End If
         Next ctl
    
         Response.Redirect("editcoordinator.aspx")
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form id="form1" runat="server">
        <p>
            EDIT COORDINATOR&nbsp; 
        </p>
        <p>
            Last Name: 
            <asp:TextBox id="lname"
runat="server"></asp:TextBox>
            &nbsp;&nbsp;&nbsp;&nbsp; 
            <br />
            First Name:&nbsp;<asp:TextBox id="fname"
runat="server"></asp:TextBox>
            &nbsp;&nbsp; 
            <br />
            <asp:Button id="Button1"
onclick="Button1_Click" runat="server"
Text="Search"></asp:Button>
            &nbsp; 
            <asp:Button id="Button2"
onclick="Button2_Click" runat="server"
Text="Clear"></asp:Button>
        </p>
        <p>
            <asp:DataGrid id="dgCoordinator"
runat="server" DataKeyField="UserUID"
AutoGenerateColumns="False"
OnCancelCommand="dgCoordinator_Cancel"
OnUpdateCommand="dgCoordinator_Update"
OnEditCommand="dgCoordinator_Edit" BorderStyle="None"
BorderWidth="1px" BorderColor="#E7E7FF"
BackColor="White" CellPadding="3" Font-Names="Arial"
GridLines="Horizontal">
                <FooterStyle forecolor="#4A3C8C"
backcolor="#B5C7DE"></FooterStyle>
                <HeaderStyle font-bold="True"
forecolor="#F7F7F7" backcolor="#4A3C8C"></HeaderStyle>
                <PagerStyle horizontalalign="Right"
forecolor="#4A3C8C" backcolor="#E7E7FF"
mode="NumericPages"></PagerStyle>
                <SelectedItemStyle font-size="X-Small"
font-bold="True" forecolor="#F7F7F7"
backcolor="#738A9C"></SelectedItemStyle>
                <EditItemStyle
font-size="X-Small"></EditItemStyle>
                <AlternatingItemStyle
font-size="X-Small"
backcolor="#F7F7F7"></AlternatingItemStyle>
                <ItemStyle font-size="X-Small"
forecolor="#4A3C8C" backcolor="#E7E7FF"></ItemStyle>
                <Columns>
                    <asp:EditCommandColumn
ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
                    <asp:BoundColumn
DataField="UserUID" ReadOnly="True"
HeaderText="UserUID"></asp:BoundColumn>
                    <asp:BoundColumn
DataField="Username"
HeaderText="Username"></asp:BoundColumn>
                    <asp:BoundColumn
DataField="Password"
HeaderText="Password"></asp:BoundColumn>
                    <asp:BoundColumn
DataField="LastName" HeaderText="Last
Name"></asp:BoundColumn>
                    <asp:BoundColumn
DataField="FirstName" HeaderText="First
Name"></asp:BoundColumn>
                    <asp:BoundColumn DataField="Email"
HeaderText="Email"></asp:BoundColumn>
                    <asp:BoundColumn DataField="Phone"
HeaderText="Phone"></asp:BoundColumn>
                    <asp:BoundColumn
DataField="Region"
HeaderText="Region"></asp:BoundColumn>
                </Columns>
            </asp:DataGrid>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
            <asp:Label id="Label1" runat="server"
forecolor="Red"></asp:Label>
        </p>
        <p>
            <asp:Label id="Label2" runat="server"
forecolor="Red"></asp:Label>
        </p>
        <!-- Insert content here -->
    </form>
</body>
</html>
=====================================================
--- Karthick Kumar <[EMAIL PROTECTED]>
wrote:

> OK Check these..
> 
> 
> 1. In Edit Event handler, make sure the following
> are done:
> 
> Your datagrid.EditItemIndex = e.Item.ItemIndex
> Bind datagrid()
> 
> 2. In Update Event handler, make sure the following
> are done:
> 
> <your code for updating the table...>
> 
> Your datagrid.EditItemIndex = -1
> Bind datagrid()
> 
> And if it doesn't works this time, it is better you
> copy + paste the code
> here... 
> 
> Hth,
> Karthick
> 
> 
> -----Original Message-----
> From: Anna Leon [mailto:[EMAIL PROTECTED] 
> Sent: 01 October 2004 15:22
> To: [EMAIL PROTECTED]
> Subject: RE: [AspNetAnyQuestionIsOk] Datagrid Edit
> 
> 
> Yes I have all of that.
> 
> But after UPDATE occur, the datagrid is rebinded
> with
> the updated info. You see the record plus the EDIT
> buttoncolumn again. BUT if the user decides to click
> on EDIT again, no record is returned and the
> datagrid
> becomes empty.
> 
> Is there any way to go about that?
> 
> --- Karthick Kumar <[EMAIL PROTECTED]>
> wrote:
> 
> > Hi,
> > 
> > Follow this:
> > 
> > 1. Bind the datagrid with your SQL Select query
> and
> > have in databound(ed)
> > [make sure the values are displaye din the
> datagrid]
> > 
> > 2. Include the Edit, Update, Cancel template
> column
> > in your datagrid
> > 
> > 3. Write the Edit, update and Cancel event
> handlers
> > 
> > 4. Once the Update event is fired, bind the
> datagrid
> > once again to show the
> > updated values
> > 
> > If you still, can't resolve then you got to post
> > your datagrid and update
> > event handler code
> > 
> > Hth,
> > Karthick
> > 
> > 
> > -----Original Message-----
> > From: Anna Leon [mailto:[EMAIL PROTECTED] 
> > Sent: 01 October 2004 14:43
> > To: [EMAIL PROTECTED]
> > Subject: RE: [AspNetAnyQuestionIsOk] Datagrid Edit
> > 
> > Actually, when a user edits/updates a record, the
> > datagrid is rebinded with the updated info. But if
> > the
> > user forgot something and clicks EDIT again, the
> > datagrid becomes empty (no record is returned).
> How
> > to
> > solve that?
> > 
> > --- Karthick Kumar
> <[EMAIL PROTECTED]>
> > wrote:
> > 
> > > Use the DataKeyField property in your Data Grid
> to
> > > get the UID (hopefully
> > > you are getting it in your select query from the
> > > DB). Also, don't forget to
> > > bind your Data Grid in the code, once the
> editing
> > is
> > > done.
> > > 
> > > Also, follow this link to get more info on
> Editing
> > > Data Grids:
> > > http://url123.com/nhkwp
> > > 
> > > Hth,
> > > Karthick
> > > 
> > > 
> > > -----Original Message-----
> > > From: sas0riza [mailto:[EMAIL PROTECTED] 
> > > Sent: 01 October 2004 02:32
> > > To: [EMAIL PROTECTED]
> > > Subject: [AspNetAnyQuestionIsOk] Datagrid Edit
> > > 
> > > 
> > > I have a search form, where user enters in last
> > name
> > > and first name. 
> > > The record is then returned to the datagrid.
> > > 
> > > When the user actually EDITS the last name
> and/or
> > > first name, and 
> > > then hit UPDATE, the updated row does not get
> > > returned to the 
> > > datagrid because the function is still passing
> in
> > > the old parameters 
> > > (whatever was originally entered into last
> > > name/first name).
> > > 
> > > I would like to obtain the UID of whatever row
> the
> > > user clicks EDIT 
> > > on, and use that as my parameter in my
> functions.
> > > 
> > > How should I go about it?
> > > 
> > > Thanks.
> > > 
> > > 
> > > 
> > > 
> > >  
> > > Yahoo! Groups Links
> > > 
> > > 
> > > 
> > >  
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > 
> > 
> > 
> >             
> > _______________________________
> > Do you Yahoo!?
> > Declare Yourself - Register online to vote today!
> > http://vote.yahoo.com
> > 
> > 
> > 
> >  
> > Yahoo! Groups Links
> > 
> > 
> > 
> >  
> > 
> > 
> > 
> > 
> 
> 
> 
>               
> __________________________________
> Do you Yahoo!?
> New and Improved Yahoo! Mail - Send 10MB messages!
> http://promotions.yahoo.com/new_mail 
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 
> 
> 
> 
> 



                
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com


------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to