Hi all,
I'm having a difficulties here. I create a RadGrid and use an EditFormSettings for inserting new data. Within the EditFormSettings , I have a RadAutoCompleteBox ID="plant" which will get the value from database. I want, when Users choose the Plant in RadAutoCompleteBox, system will parse the value of Latitude & Longitude to the RadTextBox which defined.
My challenge here, I'm able to retrieve the Latitude & Longitude value but unable to assign to the respective textbox.
Please help..
My code as below;
C#
protected void Plant_TextChanged(object sender, Telerik.Web.UI.AutoCompleteEntryEventArgs e){ string a = e.Entry.Text; foreach (GridEditableItem item in RadGrid2.EditItems) { RadTextBox lati = (RadTextBox)item.FindControl("plantLat2"); RadTextBox longi = item.FindControl("plantLong2") as RadTextBox; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ibmsConnectionString"].ToString()); SqlCommand cmd = new SqlCommand("plant_GPS_list", con); SqlDataAdapter da = new SqlDataAdapter(cmd); con.Open(); da.SelectCommand.CommandType = CommandType.StoredProcedure; da.SelectCommand.Parameters.Add("@Plant", SqlDbType.VarChar, 50); da.SelectCommand.Parameters["@Plant"].Value = a; SqlDataReader dr = da.SelectCommand.ExecuteReader(); try { if (dr.Read()) { lati.Text = dr["Latitude"].ToString(); longi.Text = dr["Longitude"].ToString(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } con.Close(); }}ASPX
<telerik:RadGrid ID="RadGrid2" runat="server" DataSourceID="SqlDataSource2" OnDetailTableDataBind="RadGrid2_DetailTableDataBind" OnNeedDataSource="RadGrid2_NeedDataSource" AllowFilteringByColumn="True" AllowPaging="True" OnItemCreated="RadGrid2_ItemCreated" OnInsertCommand="RadGrid2_InsertCommand" OnItemDataBound="RadGrid2_ItemDataBound" OnItemCommand="RadGrid2_ItemCommand"> <GroupingSettings CollapseAllTooltip="Collapse all groups" /> <MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource2" DataKeyNames="Plant" CommandItemDisplay="Top"> <CommandItemTemplate> <div style="padding: 10px 10px; color: #2B373D !important; font-weight: bold;"> <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" Visible='<%# !RadGrid2.MasterTableView.IsItemInserted %>'> <i class="fa fa-plus"></i> Add Platform / Plant </asp:LinkButton> </div> </CommandItemTemplate> <Columns> .... </Columns> <DetailTables> <telerik:GridTableView Name="BpName"> ....... </telerik:GridTableView> </DetailTables> <EditFormSettings EditFormType="Template"> <FormTemplate> <div class="form-horizontal"> <div class="form-group"> <div class="col-md-2 control-label"> Plant :</div> <div class="col-md-10"> <div class="form-inline"> <div class="form-group"> <telerik:RadAutoCompleteBox ID="plant" runat="server" DataSourceID="dsPlant" DataTextField="Plant" OnEntryAdded="Plant_TextChanged" DataValueField="Plant" InputType="Token" Width="300px" AllowCustomEntry="true" AutoPostBack="True"> <TextSettings SelectionMode="Single" /> </telerik:RadAutoCompleteBox> </div> <div class="form-group"> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="plant" ErrorMessage="* Please insert Plant." Font-Bold="True" ForeColor="Red" SetFocusOnError="True"> </asp:RequiredFieldValidator> </div> </div> </div> </div> <div class="form-group"> <label class="col-md-2 control-label"> GPS Location :</label> <div class="col-md-10"> <div class="form-horizontal"> <div class="form-group"> <label class="col-sm-12 col-md-1 control-label"> Latitude </label> <div class="col-sm-12 col-md-10"> <telerik:RadTextBox ID="plantLat2" runat="server" Text='<%# Bind( "Latitude") %>'> </telerik:RadTextBox> <asp:RangeValidator ID="LatRangeValidator2" runat="server" ControlToValidate="plantLat2" ErrorMessage="* Choose a coordinate between -90 and 90 degrees inclusive." Font-Bold="true" ForeColor="Red" MaximumValue="90" MinimumValue="-90" EnableClientScript="False" Type="Double" SetFocusOnError="True"> </asp:RangeValidator> </div> </div> <div class="form-group"> <label class=" col-sm-12 col-md-1 control-label"> Longitude </label> <div class="col-sm-12 col-md-10"> <telerik:RadTextBox ID="plantLong2" runat="server" Text='<%# Bind( "Longitude") %>'> </telerik:RadTextBox> <asp:RangeValidator ID="LongRangeValidator2" runat="server" ControlToValidate="plantLong2" ErrorMessage="* Choose a coordinate between -180 and 180 degrees inclusive." Font-Bold="true" ForeColor="Red" MaximumValue="180" MinimumValue="-180" EnableClientScript="False" Type="Double" SetFocusOnError="True"> </asp:RangeValidator> </div> </div> </div> </div> </div> <div class="form-group"> <div class="col-md-2 control-label"> </div> <div class="col-md-10"> <asp:Button ID="plantUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' CssClass="btn btn-warning" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'> </asp:Button> <asp:Button ID="plantCancel" Text="Cancel" runat="server" CausesValidation="False" CssClass="btn btn-info" CommandName="Cancel"></asp:Button> </div> </div> </div> </FormTemplate> </EditFormSettings> </MasterTableView></telerik:RadGrid>