Hi !
I'm trying to resolve a problem for a long time now without success and I really can’t find a solution…. Please, help me…
My problem is in the RadGrid1_UpdateCommand()
I can’t get a value from a RadNumericTextBox
Well, I get the value, but when there is a multiple edited values, my code only get the last edited value of the RadNumericTextBox
What I want to do :
I have 3 tables in my databases :
PRODUCTS
product_id
group_ref
…
CATEGORIES
category_id
…
LINKS
link_id
link_product_id
link_category_id
link_points
See my attached image to see the links between them..
This is my select command to fill the radgrid :
select distinct group_ref, link_points, link_category_id
FROM LINKS
INNER JOIN PRODUCTS ON PRODUCTS.product_id = LINKS.link_product_id
WHERE link_category_id=10
ORDER BY link_points desc, group_ref
I want to update all link_points that are associated to a link_category_id AND a group_ref
In the PRODUCTS Table, many products can have the same group_ref value.
So, this is my update command I want to do :
UPDATE LINKS SET link_points = ???
FROM LINKS
INNER JOIN PRODUCTS ON PRODUCTS.product_id = LINKS.link_product_id
WHERE group_ref ='xxxxx' AND link_category_id=xxxxx
This is my Radgrid html code :
<telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AllowAutomaticInserts="false" AllowAutomaticDeletes="false" AllowAutomaticUpdates="True"
Skin="Metro" Width="100%" OnLoad="Unnamed_Load1" PageSize="100" AllowPaging="True" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
OnPreRender="RadGrid1_PreRender" OnItemDataBound="RadGrid1_ItemDataBound" OnUpdateCommand="RadGrid1_UpdateCommand">
<PagerStyle Mode="NextPrevAndNumeric" Position="Bottom" PageSizeLabelText="Nombre de ligne(s) :" PageSizeControlType="None" PageSizes="100"
NextPageToolTip="Page suivante" PrevPageToolTip="Page précédente" FirstPageToolTip="Première page" LastPageToolTip="Dernière page" />
<MasterTableView CommandItemDisplay="TopAndBottom" AllowAutomaticInserts="false" EditMode="Batch" InsertItemDisplay="bottom" AllowAutomaticUpdates="true"
DataSourceID="SqlDataSource1" HorizontalAlign="NotSet" AutoGenerateColumns="False">
<BatchEditingSettings EditType="Cell" />
<SortExpressions>
<telerik:GridSortExpression FieldName="group_ref" SortOrder="Descending" />
</SortExpressions>
<Columns>
<telerik:GridBoundColumn DataField="link_category_id" HeaderText="Produit matière" ReadOnly="true"
ItemStyle-HorizontalAlign="left" HeaderStyle-HorizontalAlign="left"
SortExpression="link_category_id" UniqueName="link_category_id">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="group_ref" HeaderText="Ref. de groupe" ReadOnly="true"
ItemStyle-HorizontalAlign="left" HeaderStyle-HorizontalAlign="left"
SortExpression="group_ref" UniqueName="group_ref">
</telerik:GridBoundColumn>
<telerik:GridNumericColumn DataField="link_points"
ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Width="100px" HeaderText="Classement" ItemStyle-Width="100px"
SortExpression="link_points" UniqueName="link_points">
</telerik:GridNumericColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<Selecting AllowRowSelect="True"></Selecting>
</ClientSettings>
</telerik:RadGrid>
And this is my code behind :
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
GET_SELECT_CMD()
End If
End Sub
Private Sub GET_SELECT_CMD()
Dim sscatid As String = Trim(Request.QueryString("o"))
Dim strCmd As String = "select distinct group_ref, link_points, link_category_id "
strCmd = strCmd & " from LINKS "
strCmd = strCmd & " INNER JOIN PRODUCTS ON PRODUCTS.product_id = LINKS.link_product_id "
strCmd = strCmd & " WHERE link_category_id=" & sscatid & " "
strCmd = strCmd & " ORDER BY link_points desc, group_ref "
SqlDataSource1.SelectCommand = strCmd
RadGrid1.MasterTableView.BatchEditingSettings.OpenEditingEvent = GridBatchEditingEventType.Click
End Sub
Protected Sub Unnamed_Load1(sender As Object, e As EventArgs)
GET_SELECT_CMD()
End Sub
Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs)
Dim db As New DAL_SQL
Try
Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
Dim TriNumericTextBox As RadNumericTextBox = TryCast(item.OwnerTableView.GetBatchColumnEditor("link_points"), GridNumericColumnEditor).NumericTextBox
Dim strTriValue As String = TriNumericTextBox.Text.ToString()
Dim strSsCatId As String = Trim(Request.QueryString("o"))
Dim strRefGroupe As String = item.Cells(3).Text
If Not ((strTriValue <> "") And IsNumeric(strTriValue)) Then
strTriValue = "0"
End If
Dim sql_upd As String = "UPDATE LINKS SET link_points = " & strTriValue & " "
sql_upd = sql_upd & " FROM LINKS "
sql_upd = sql_upd & " INNER JOIN PRODUCTS ON PRODUCTS.product_id = LINKS.link_product_id "
sql_upd = sql_upd & " WHERE group_ref='" & strRefGroupe & "' AND link_category_id=" & strSsCatId
db.ExecuteNonQuery(sql_upd)
Catch ex As Exception
ErrTxt = ex.ToString()
End Try
db = Nothing
End Sub
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
If TypeOf e.Item Is GridCommandItem Then
Dim addButton As Button = TryCast(e.Item.FindControl("AddNewRecordButton"), Button)
addButton.Visible = False
Dim lnkButton As LinkButton = DirectCast(e.Item.FindControl("InitInsertButton"), LinkButton)
lnkButton.Visible = False
End If
End Sub
Everything works fine, but the line in RadGrid1_UpdateCommand() only get the last edited value and not the value of each item edited :
Dim TriNumericTextBox As RadNumericTextBox = TryCast(item.OwnerTableView.GetBatchColumnEditor("link_points"), GridNumericColumnEditor).NumericTextBox
How can I get the value of each RadNumericTextBox ?
Thanks a lot for every help you could give to me.