I'm trying to select an item value from DropDownTree which impeded in a RadGrid , in the add new record in the radGrid then select the item from dropdownTree , but i can't find a way to access the radgrid cell to update its value by the DropDownTree value ,
the scenario is get the itemCode value from DropDownTree then search in Database to get the Item Price then put the price in the RadGrid
Protected Sub RadDropDownTree1_EntryAdded(sender As Object, e As DropDownTreeEntryEventArgs)GetItemPrice(e.Entry.Value)
End Sub
Private Sub GetItemPrice(Item_code As Int32)
Dim ConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim conn As SqlConnection = New SqlConnection(ConnString)
Dim command As SqlCommand = New SqlCommand()
Dim myreader As SqlDataReader
command.CommandText = "[dbo].[FindItemPrice]"
command.CommandType = CommandType.StoredProcedure
conn.Open()
command.Connection = conn
command.Parameters.AddWithValue("ItemCode", Item_code)
Try
myreader = command.ExecuteReader()
If myreader.Read() Then
Dim ItemGrid As RadGrid = CType(Page.Master.FindControl("MainContent").FindControl("RadGrid2"), RadGrid)
For Each item As GridDataItem In ItemGrid.MasterTableView.Items
Dim tx As TextBox = TryCast(item.FindControl("Price"), TextBox)
tx.Text = myreader("Unit_Price")
Next
Else
End If
conn.Close()
Catch ex As Exception
Throw ex
End Try
End Sub
Thanks for you replay
this is the grid definition in aspx
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid2" CssClass="GridTreeAlign"
ShowStatusBar="true" runat="server"
AllowPaging="True"
AllowAutomaticUpdates="true"
AllowAutomaticInserts="True"
AllowAutomaticDeletes="True"
OnItemCreated="RadGrid2_ItemCreated"
GridLines="None" AutoGenerateColumns="false"
PageSize="5" DataSourceID="SqlDataSource3">
<MasterTableView Width="100%" AutoGenerateColumns="False" style="text-align: -webkit-right;"
DataKeyNames="ItemHeaderId,Id" EditMode="InPlace" CommandItemDisplay="Top"
ShowFooter="false" DataSourceID="SqlDataSource3" InsertItemDisplay="Top"
InsertItemPageIndexAction="ShowItemOnFirstPage">
<CommandItemSettings ExportToPdfText="Export to PDF" AddNewRecordText="أضافة عنصر جديد" CancelChangesText="تراجع" SaveChangesText="حفظ" RefreshText="أعادة تنشيط"></CommandItemSettings>
<Columns>
<telerik:GridBoundColumn ReadOnly="true" DataField="ItemHeaderId" Display="false" HeaderText="كود ت" SortExpression="ItemHeaderId" ItemStyle-Width="100px" HeaderStyle-Width="100px"
UniqueName="ItemHeaderId">
<HeaderStyle ForeColor="Silver"></HeaderStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn ReadOnly="true" DataField="Id" HeaderText="كود ص" Display="false" SortExpression="Id" ItemStyle-Width="100px" HeaderStyle-Width="100px"
UniqueName="Id">
<HeaderStyle ForeColor="Silver"></HeaderStyle>
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="إسم الصنف" ItemStyle-Width="400px">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "Item_Name")%>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDropDownTree RenderMode="Lightweight" runat="server" dir="rtl" CssClass="dropdownTree" ID="RadDropDownTreeTest"
DataTextField="Item_Name"
DataFieldParentID="Parent_Id"
DataFieldID="Child_Id"
DataValueField="Item_Code"
DataSourceID="SqlDataSource4"
OnDataBound="RadDropDownTreeTest_DataBound"
AutoPostBack="true"
ExpandNodeOnSingleClick="true"
OnEntryAdded="RadDropDownTree1_EntryAdded"
SelectedValue='<%#Bind("Item_Code") %>' DefaultMessage="اختـــار الصـــنف من فضـــــلك"
DefaultValue="1" DropDownSettings-AutoWidth="Enabled"
DropDownSettings-OpenDropDownOnLoad="True"
EnableFiltering="True"
FilterSettings-EmptyMessage="أكتب اسم الصنف"
Font-Bold="True"
DropDownSettings-Width="400px" Width="400px">
<DropDownSettings OpenDropDownOnLoad="true"
Width="400px" CloseDropDownOnSelection="true" AutoWidth="Enabled" />
<ExpandAnimation Type="InBounce" Duration="300" />
<CollapseAnimation Type="OutQuint" Duration="200" />
</telerik:RadDropDownTree>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="Price" HeaderText="سعر الصنف" SortExpression="Price"
UniqueName="Price" HeaderStyle-Width="100px" ItemStyle-Width="100px">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Qty" HeaderText="الكمية" SortExpression="Qty" HeaderStyle-Width="100px" ItemStyle-Width="100px"
UniqueName="Qty">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Total" HeaderText="الإجمالي" ReadOnly="true" SortExpression="Total" HeaderStyle-Width="100px" ItemStyle-Width="100px"
UniqueName="Total">
</telerik:GridBoundColumn>
<telerik:GridEditCommandColumn HeaderText="تعديل" UniqueName="EditCommandColumn">
<HeaderStyle Width="20px" ></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn ConfirmText="حذف هذا الصنف نهائيا؟" HeaderText="حذف"
CommandName="Delete" Text="حذف" UniqueName="DeleteColumn" ConfirmDialogType="RadWindow" ButtonType="FontIconButton" ConfirmTitle="برنامج المثمن">
<HeaderStyle Width="20px" ></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
</telerik:GridButtonColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowKeyboardNavigation="true" >
<Selecting AllowRowSelect="true"></Selecting>
</ClientSettings>
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
</telerik:RadGrid>
then he code behind
Protected Sub RadDropDownTree1_EntryAdded(sender As Object, e As DropDownTreeEntryEventArgs)GetItemPrice(e.Entry.Value)
' RadGrid2.RenderClientStateField()
End Sub
Private Sub GetItemPrice(Item_code As Int32)
Dim ConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim conn As SqlConnection = New SqlConnection(ConnString)
Dim command As SqlCommand = New SqlCommand()
Dim myreader As SqlDataReader
command.CommandText = "[dbo].[FindItemPrice]"
command.CommandType = CommandType.StoredProcedure
conn.Open()
command.Connection = conn
command.Parameters.AddWithValue("ItemCode", Item_code)
Try
myreader = command.ExecuteReader()
If myreader.Read() Then
Dim ItemGrid As RadGrid = CType(Page.Master.FindControl("MainContent").FindControl("RadGrid2"), RadGrid)
Dim dataItm As GridDataItem = TryCast(ItemGrid.MasterTableView.Items(-1), GridDataItem)
Dim cell As TableCell = dataItm("price")
cell.Text = Convert.ToString(myreader("Unit_Price"))
cell.Focus()
cell.BorderColor = Color.Red
End If
conn.Close()
Catch ex As Exception
Throw ex
End Try
End Sub