ASP.NET: DetailsView OnItemInserting is not working

tommynemec

New Member
I have created a \[code\]DetailsView\[/code\] and added \[code\]OnItemInserting\[/code\] Event to get values in \[code\]txt_gps_coordinates\[/code\] and separate value in \[code\]txt_gps_coordinates\[/code\] on code behind and set as text of \[code\]txt_latitude\[/code\] and \[code\]txt_longitude\[/code\] as below. but it's not working. what could be the issue ?\[code\]<asp:DetailsView ID="Area_DV" runat="server" AutoGenerateRows="False" DefaultMode="Insert" DataKeyNames="AREA_ID" DataSourceID="Area_EDS" OnItemInserting="Area_DV_ItemInserting"> <Fields> // other fields here <asp:TemplateField HeaderText="GPS Coordinates" SortExpression="LATITUDE"> <EditItemTemplate> <asp:TextBox ID="TextBox20" runat="server"></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="txt_gps_coordinates" Width="200" runat="server"></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label30" runat="server"></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Latitude" SortExpression="LATITUDE" Visible="false"> <EditItemTemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("LATITUDE") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="txt_latitude" Width="200" runat="server" Text='<%# Bind("LATITUDE") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("LATITUDE") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Longitude" SortExpression="LONGITUDE" Visible="false"> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("LONGITUDE") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="txt_longitude" Width="200" runat="server" Text='<%# Bind("LONGITUDE") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label4" runat="server" Text='<%# Bind("LONGITUDE") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:CommandField ShowInsertButton="True" CancelText="Reset" /> </Fields> </asp:DetailsView>\[/code\]Code behind\[code\] protected void Area_DV_ItemInserting(Object sender, DetailsViewInsertEventArgs e) { TextBox GpsCoordinates = (TextBox)Area_DV.FindControl("txt_gps_coordinates"); TextBox latitude = (TextBox)Area_DV.FindControl("txt_latitude"); TextBox longitude = (TextBox)Area_DV.FindControl("txt_longitude"); string[] coordinates = GpsCoordinates.Text.Trim().Split(','); latitude.Text = coordinates[0]; longitude.Text = coordinates[1]; }\[/code\]How could i solve this ? my need is get comma separated value in \[code\]txt_gps_coordinates\[/code\] and separate that value and set separated value as text of \[code\]txt_latitude\[/code\] and \[code\]txt_longitude\[/code\]. when user submit form, database columns \[code\]LATITUDE\[/code\] and \[code\]LONGITUDE\[/code\] should be fill fith those values.
 
Back
Top