hello - trying to forrest gump my way though a simple webdatagrid with the option to add a row. the row adding seems to work (as does the row deleting - although we receive a Async request failed with a keynotfoundexception). not sure why this is happending. here is my markup and code behind:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:SqlDataSource ID="ds_Parts" runat="server"
ConnectionString="<%$ ConnectionStrings:CustomQuoteConnectionString %>"
SelectCommand="select * from PartMasterRelatedParts inner join partmaster on partmaster.partnumber = PartMasterRelatedParts.OriginalPartNumber where PartMasterRelatedParts.OriginalPartNumber = @id"
SelectCommandType="Text"
InsertCommand="insert into PartMasterRelatedParts (OriginalPartNumber,RelatedPartNumber) values (@OriginalPartNumber, @RelatedPartNumber) "
InsertCommandType="Text"
DeleteCommand="delete from PartMasterRelatedParts where RelatedPartID = @RelatedPartID"
DeleteCommandType="Text" >
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID" />
</SelectParameters>
<InsertParameters >
<asp:Parameter Name="OriginalPartNumber" Type="String" />
<asp:Parameter Name="RelatedPartNumber" Type="String"/>
</InsertParameters>
<DeleteParameters>
<asp:Parameter Name="RelatedPartID" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>
<p>
<asp:HyperLink ID="HyperLink1" runat="server"><<== back to part</asp:HyperLink>
</p>
<p></p>
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Width="96%" AutoGenerateColumns="False"
DataSourceID="ds_Parts" DataKeyFields="RelatedPartID"
OnRowAdding="WebDataGrid1_RowAdding"
OnRowDeleted="WebDataGrid1_RowDeleting" >
<Columns>
<ig:BoundDataField DataFieldName="RelatedPartID" Key="RelatedPartID" Hidden="true"></ig:BoundDataField>
<ig:BoundDataField DataFieldName="RelatedPartNumber" Key="RelatedPartNumber">
<Header Text="Related Part #" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="Description" Key="Description">
<Header Text="Description" />
</Columns>
<Behaviors>
<ig:EditingCore>
<ig:CellEditing>
</ig:CellEditing>
<ig:RowAdding >
<EditModeActions MouseClick="Single" />
</ig:RowAdding>
<ig:RowDeleting />
</Behaviors>
</ig:EditingCore>
<ig:Selection CellClickAction="Row" RowSelectType="Single">
</ig:Selection>
<ig:RowSelectors>
</ig:RowSelectors>
<ig:Sorting>
</ig:Sorting>
</ig:WebDataGrid>
===================
=================== here is the code-behind
Imports
System.Web.UI.Page
System
System.Data
System.Configuration
System.Web
System.Web.Security
System.Web.UI
System.Web.UI.WebControls
System.Web.UI.WebControls.WebParts
System.Web.UI.HtmlControls
System.Data.SqlClient
System.Web.Configuration
Infragistics.Web.UI.GridControls
Partial
Class Parts_relatedParts
Inherits System.Web.UI.Page
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs) Handles Me.Load
HyperLink1.NavigateUrl =
"/parts/editpart.asp?id=" & Request.QueryString("ID")
HyperLink1.Target =
"_parent"
End Sub
Protected Sub WebDataGrid1_RowAdding(ByVal sender As Object, ByVal e As Infragistics.Web.UI.GridControls.RowAddingEventArgs) Handles WebDataGrid1.RowAdding
Dim Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("CustomQuoteConnectionString").ConnectionString)
Dim cmd As SqlCommand
Dim strSQL As String
strSQL =
"insert into PartMasterRelatedParts (OriginalPartNumber,RelatedPartNumber) values (" & _
"'" & Request.QueryString("ID") & "', " & _
"'" & e.Values("RelatedPartNumber") & "') "
cmd =
New SqlCommand(strSQL, Conn)
cmd.CommandType =
CommandType.Text
Conn.Open()
cmd.ExecuteNonQuery()
Conn.Close()
'Response.Redirect("/parts/editpart.asp?ID=" & Request.QueryString("ID"))
Protected Sub WebDataGrid1_RowDeleting(ByVal sender As Object, ByVal e As Infragistics.Web.UI.GridControls.RowDeletedEventArgs) Handles WebDataGrid1.RowDeleted
"delete from PartMasterRelatedParts where RelatedPartID = " & _
"'" & e.RowID("RelatedPartID")
End
Class
not sure what i am doing wrong - any help would be appreciated.
thanks!
Hello Emil,
Thank you for posting in Infragistics forum!
In the described scenario, the issue most likely occurs as the grid is configured to use automatic crud (the EditingCore's AutoCRUD property is True by default) but at the same time the CRUD operations are configured manually. When attempting to add a new row in this case, the RowAdding event is fired first and the row is added once to the DB manually. Afterwards the grid's automatic add functionality kicks in, adding the row a second time. A similar thing is happening when deleting - the row is first manually deleted, and afterwards the grid attempts to delete it one more time. More information about how to perform Auto and Manul CRUD operations is explained in the following videos: http://www.infragistics.com/products/aspnet/data-grid/videos/webdatagrid-manual-create-read-update-delete
http://www.infragistics.com/products/aspnet/data-grid/videos/webdatagrid-automatic-create-read-update-dele
I would therefore suggest setting the AutoCRUD property to false in order to check if it resolves the issue. If you have any further questions, please feel free to contact me.
Sincerely,
Tsanna
I'm still following your case. Have you been able to resolve the issue? Please let me know if you need more assistance.