Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ok....i give up...... 1

Status
Not open for further replies.

threeo

Programmer
Mar 31, 2005
49
US
can anyone out there explain this......

i have a datagrid which has an "edit", "update" and "cancel" set up like this:

<asp:datagrid id=dgNormTypes runat="server" DataSource="<%# DataSet61 %>" AutoGenerateColumns="False" DataKeyField="NORM_TYPE" Width="60%" OnUpdateCommand="DoItemUpdate" OnEditCommand="DoItemEdit" OnCancelCommand="DoItemCancel">
<ItemStyle Font-Size="9pt" Font-Names="Tahoma" ForeColor="#006699" BackColor="#E0E0E0"></ItemStyle>
<HeaderStyle Font-Size="9pt" Font-Names="Tahoma" Font-Bold="True" Wrap="False" ForeColor="White"
BackColor="#006699"></HeaderStyle>
<Columns>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" />
" runat="server">
etc.....

then i have the corresponding 3 subroutines "DoItemCancel", "DoItemEdit" and "DoItemUpdate"

for some reason......the DoItemCancel and DoItemUpdate subroutines never execute their code. the DoItemEdit does execute it's code just fine. i can even just make DoItemUpdate have a single response.write("hello") and it never gets written to the page. i can tell that all three do a postback but no matter what.....the code within DoItemUpdate and DoItemCancel never execute. it get's even more perplexing because....i put a response.write("edit") at the end of the code for DoItemEdit. when i hit Edit, it does what it is supposed to do (revealing the Update and Cancel in place of the Edit) and at the top of the page i see the "edit" (from the response.write) - now here's the really strange part......when i click "Update"......i see the page reloaded and AGAIN i see "edit" at the top of the page. it is as though "Update" executes the code inside of "DoItemEdit"
and when i click "Cancel"...it does exactly what i want it to do (closes every thing back up and reveals "Edit" in place of the "Update" and "Cancel") - but....i have no idea HOW or WHY it works as there is no code in the DoItemCancel subroutine! - (the "edit" does not get written to the page when i click Cancel like it does when i click "Update")

anyone have any ideas as to why?

threeo
 
well.....
i did have a bunch of code in doitemupdate and it wasn't working so i removed it and just stuck in:
Sub DoItemUpdate(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)

response.write("update")

end sub

just to see if i could get ANY code to execute.....

it never writes out the "update" to the page when i click Update

instead....

it writes out "edit"

which is the response.write i put inside the DoItemEdit subroutine

???
 
are you rebinding the grid after the update?

you really should post your code

 
ok...here it is.... (i was just trying to get it to do ANYTHING - that's why i had reduced it to a simple response.write)

Sub DoItemUpdate(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
' get a reference to the DataGrid control in this row
Dim oRow As DataListItem = dlOperations.Items(dlOperations.SelectedIndex)
Dim oGrid As DataGrid = CType(oRow.FindControl("dgNormTypes"), DataGrid)

' set the EditItemIndex of the grid to this item's index
oGrid.EditItemIndex = e.Item.ItemIndex

' get a reference to the text box
Dim oResults As TextBox = CType(e.Item.FindControl("txtResults"), TextBox)
' set EditItemIndex of grid to -1 to switch out of Edit mode
oGrid.EditItemIndex = -1
oGrid.DataSource = DataSet121
oGrid.DataBind()
End Sub
 
actually....it seems like it doesn't matter what code is in the DoItemUpdate because.....it never GETS to it. it never response. wrote out the "update" that i stuck in it. and, it never executed the original code that was there. in fact....it response . wrote out the "edit" from the DoItemEdit!

 
Handles YourGridName.UpdateCommand

add that as follows

Sub DoItemUpdate(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)Handles YourGridName.UpdateCommand

now find the control

Dim strName As String = CType(e.Item.FindControl("txtBox"), TextBox).Text

add

Response.Write(e.Item.Cells(0).Text)

Dim strSQL as String = "UPDATE BLAAA"

Dim cn As SqlConnection = New SqlConnection()

Dim cmdExp As SqlCommand

cn.Open()

cmdExp = New SqlCommand(strSQL, cn)

Dim NameParam As New SqlParameter("@Name", SqlDbType.VarChar, 10)

NameParam.Value = strName

cmdExp.Parameters.Add(NameParam)

cmdExp.ExecuteNonQuery()

cn.Close

YourGrid.EditItemIndex = -1

BindYourGrid


This should work if your using SQL Server. There are many other ways to do this. I am sure there will be more post's.

Hope this helps







 
thanks man.
i can't wait to try this tomorrow.

thanks for taking the time....


threeo
 
darn darn darn

adding the "handles" didn't change anything.
it STILL executes the "DoItemEdit" code whenever i click "Update" (i know this because i set a label equal to the label's value plus 1 at the end of the DoItemEdit subroutine and when i click "Edit" the label increments AND when i click "Update" it also increments)

soooo....the cruxt of my problem is this: Edit and Update....BOTH execute the DoItemEdit subroutine.

here's both subroutines:
Sub DoItemEdit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)Handles dgNormTypes.EditCommand
' get a reference to the DataGrid control in this row
Dim oRow As DataListItem = dlOperations.Items(dlOperations.SelectedIndex)
Dim oGrid As DataGrid = CType(oRow.FindControl("dgNormTypes"), DataGrid)

' set the EditItemIndex of the grid to this item's index
oGrid.EditItemIndex = e.Item.ItemIndex
' bind grid to display row in new mode
' get CustomerID from the DataKeys collection of the DataList
oGrid.DataSource = DataSet61
oGrid.DataBind()
lblRecordCount.Visible = True
lblRecordCount.Text = CStr(CInt(lblRecordCount.Text) + 1)

End Sub


Sub DoItemUpdate(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles dgNormTypes.UpdateCommand
'first, determine if the original data came from IFS or
'from the sql stakqmanscanned table. this will determine
'whether this is an update to IFS, an update to sql,
'or an insertion to sql
'dataset91 has the data from stakqmanscanned
'dataset 121 has the data from IFS
'first, see if there is an entry in stakqmanscanned
'if there is, update it and get out
'otherwise, see if there is an entry in IFS
'if there is, update it and get out
'otherwise, do an insert into stakqmanscanned
Dim intExecuteResult As Integer = 0
' get a reference to the DataGrid control in this row
Dim oRow As DataListItem = dlOperations.Items(dlOperations.SelectedIndex)
Dim oGrid As DataGrid = CType(oRow.FindControl("dgNormTypes"), DataGrid)
If DataSet91.Tables(0).Rows.Count > 0 Then
'we have data in the stakqmanscanned so,
'update it now

' set the EditItemIndex of the grid to this item's index
oGrid.EditItemIndex = e.Item.ItemIndex

' get a reference to the text boxes
Dim oResults As TextBox = CType(e.Item.FindControl("txtResults"), TextBox)
Response.Write(oResults.Text)
ElseIf DataSet121.Tables(0).Rows.Count > 0 Then
'we have data in the IFS so,
'update it now

' set the EditItemIndex of the grid to this item's index
oGrid.EditItemIndex = e.Item.ItemIndex

' get a reference to the text boxes
Dim oResults As TextBox = CType(e.Item.FindControl("txtResults"), TextBox)
Response.Write(oResults.Text)
OracleUpdateAnalysisNormTab.CommandText = ""
OracleUpdateAnalysisNormTab.CommandText = "update analysis_norm_tab set non_conforms = " & oResults.Text & " where analysis_no = " & DataSet121.Tables(0).Rows(0).Item(2)
intExecuteResult = OracleUpdateAnalysisNormTab.ExecuteNonQuery()
Response.Write(intExecuteResult)

Else
'do insert
End If
If intExecuteResult = 1 Then

Else
End If
' set EditItemIndex of grid to -1 to switch out of Edit mode
oGrid.EditItemIndex = -1
oGrid.DataSource = DataSet121
oGrid.DataBind()
Response.Write("<br>" & DataSet121.Tables(0).Rows(0).Item(3))
End Sub


and here's the code that calls each:
<asp:datagrid id=dgNormTypes runat="server"
DataSource="<%# DataSet61 %>"
AutoGenerateColumns="False"
DataKeyField="NORM_TYPE" Width="60%" OnUpdateCommand="DoItemUpdate"
OnEditCommand="DoItemEdit"
OnCancelCommand="DoItemCancel">

<ItemStyle Font-Size="9pt" Font-Names="Tahoma" ForeColor="#006699" BackColor="#E0E0E0"></ItemStyle>

<HeaderStyle Font-Size="9pt" Font-Names="Tahoma" Font-Bold="True" Wrap="False" ForeColor="White"
Color="#006699"></HeaderStyle>
<Columns>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" />

<asp:BoundColumn DataField="NORM_TYPE" SortExpression="NORM_TYPE" ReadOnly="True" HeaderText="NormType"></asp:BoundColumn>

<asp:BoundColumn DataField="DESCRIPTION" SortExpression="DESCRIPTION" ReadOnly="True" HeaderText="Description"></asp:BoundColumn>

<asp:TemplateColumn HeaderText="Results" ItemStyle-HorizontalAlign="Right">

<ItemTemplate>
<%# Container.DataItem("TempResults") %>
</ItemTemplate>

<EditItemTemplate>
<asp:TextBox Columns="4" id="txtResults" Font-Name="Tahoma" Font-Size="9pt" ForeColor="#006699" runat="server" Text='<%# Container.DataItem("TempResults") %>' />
</EditItemTemplate>
</asp:TemplateColumn>

</Columns>
</asp:datagrid>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top