I have a radgrid. I am using usercontrol to edit/insert new record.
In usercontrol i have several dropdown, populated from DB. I neeed to update dropdown list of weatherstation based on selected state. Well, not sure why, but event firing once i click cancel/insert button. I need it to be fired when i am still in the insert/edit mode. I s this possible?
<
cc1:TabPanel ID ="locationsTab" runat="server" HeaderText="Locations">
<HeaderTemplate>Locations</HeaderTemplate>
<ContentTemplate>
<asp:UpdatePanel id="updPnlLoc" runat="server">
<ContentTemplate>
<asp:SqlDataSource SelectCommand="SELECT locations.id, locations.name, locations.weather_station_id, projects.project_code, locations.project_id, CAST(locations.project_id AS varchar(5)) + ':' + projects.name AS project_ids, projects.description, weather_station.station_name FROM projects INNER JOIN locations ON projects.id = locations.project_id left outer JOIN weather_station ON locations.weather_Station_id= weather_station.id"
ConnectionString="<%$ ConnectionStrings:ECMApp3 %>"
ID="LocationSource" runat="server" DeleteCommand="usp_crud_locations"
UpdateCommand="usp_crud_locations" EnableViewState="False"
DeleteCommandType="StoredProcedure" InsertCommand="usp_crud_locations"
InsertCommandType="StoredProcedure" UpdateCommandType="StoredProcedure">
<DeleteParameters>
<asp:ControlParameter ControlID="RadGrid1" Name="id"
PropertyName="SelectedValue" />
<asp:Parameter DefaultValue="3" Name="op" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="op" DefaultValue="2" Type="Int32" />
<asp:Parameter DefaultValue="" Name="name" />
<asp:Parameter Name="weather_stat" />
<asp:Parameter Name="id" />
<asp:Parameter Name="user" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter DefaultValue="1" Name="op" Type="Int32" />
<asp:Parameter Name="project_id" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="weather_stat" Type="Int32" />
<asp:Parameter Name="user" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="LocationSource"
GridLines="None" ShowGroupPanel="false" Skin="Outlook" ShowStatusBar="True"
onitemcommand="RadGrid1_ItemCommand"
onupdatecommand="RadGrid1_UpdateCommand" AllowAutomaticDeletes="True"
AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
onitemupdated="RadGrid1_ItemUpdated" ShowFooter="true"
oninsertcommand="RadGrid1_InsertCommand"
onitemdeleted="RadGrid1_ItemDeleted"
oniteminserted="RadGrid1_ItemInserted"
onitemcreated="RadGrid1_ItemCreated" onitemdatabound="RadGrid1_ItemDataBound" >
<MasterTableView AutoGenerateColumns="False" DataKeyNames="id" CommandItemDisplay="Top"
DataSourceID="LocationSource" GroupLoadMode="server" InsertItemDisplay="Top" AllowAutomaticInserts="true">
<CommandItemSettings ShowRefreshButton="false" ShowAddNewRecordButton="true" AddNewRecordImageUrl="img/buttons/add.png" AddNewRecordText="Add new location" />
<GroupByExpressions>
<telerik:GridGroupByExpression>
<SelectFields>
<telerik:GridGroupByField FieldAlias="ProjectIDs" FieldName="project_ids"
HeaderValueSeparator=" " />
</SelectFields>
<GroupByFields>
<telerik:GridGroupByField FieldAlias="project_ids" FieldName="project_ids"
SortOrder="Ascending" />
</GroupByFields>
</telerik:GridGroupByExpression>
</GroupByExpressions>
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="id" DataType="System.Int32" HeaderText="id"
ReadOnly="True" SortExpression="id" UniqueName="id">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText=project_id EditFormColumnIndex=0 UniqueName="project_id" Visible="false" >
<ItemTemplate >
<asp:Label runat="server" ID="project_idL" Text='<%# Eval("project_id") %>'
Visible="False"/>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="project_id" DataType="System.Int32"
HeaderText="project_id" SortExpression="project_id" UniqueName="project_id" ReadOnly="True"
Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="project_ids" DataType="System.Int32"
HeaderText="project_ids" SortExpression="project_ids" UniqueName="project_ids" ReadOnly="True"
Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn EditFormColumnIndex="0" DataField="name" HeaderText="name"
SortExpression="name" UniqueName="name" ColumnEditorID="GridTextBoxColumnEditor1">
<ItemStyle Width="200px" />
<HeaderStyle Width="200px" />
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Weather Station" EditFormColumnIndex ="0" UniqueName="weather_stat" ColumnEditorID="GridDropDownColumnEditor1" >
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("station_name") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="project_code" HeaderText="project_code"
SortExpression="project_code" UniqueName="project_code" ReadOnly="True">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="description" HeaderText="description"
SortExpression="description" UniqueName="description" Visible="false" ReadOnly="True">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn ConfirmText="Delete this location?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
UniqueName="DeleteColumn">
<ItemStyle HorizontalAlign="Center" />
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings UserControlName="ProjectEcms.ascx" EditFormType="WebUserControl" CaptionFormatString="Edit properties of Location {0}" >
<EditColumn UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
</MasterTableView>
<ClientSettings AllowDragToGroup="False">
</ClientSettings>
</telerik:RadGrid>
<telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="200px" />
<telerik:GridTextBoxColumnEditor ID="GridDropDownColumnEditor1" runat="server" TextBoxStyle-Width="350px" />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</cc1:TabPanel>
<%
@ Control Language="C#" AutoEventWireup="true" CodeFile="projectEcms.ascx.cs" Inherits="projectEcms" %>
<%
@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<
style type="text/css">
.style1
{
font-weight: bold;
font-style: italic;
color: #000099;
}
.style2
{
height: 39px;
}
</
style>
<asp:SqlDataSource ID="LProjectsSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ECMApp3 %>"
SelectCommand="select id as project_id, isnull(project_code,'')+ '|'+ name as Name from dbo.projects
union all select null, null">
</asp:SqlDataSource>
<asp:SqlDataSource ID="WeatherStationSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ECMApp3 %>" SelectCommand="select null id, null station_name
union
SELECT id, [station_name] FROM [weather_station] where state=@state">
<
SelectParameters>
<
asp:ControlParameter ControlID="StateDropDownList" Direction="Input" Name="state" Type="String" />
</
SelectParameters>
</
asp:SqlDataSource>
<
asp:SqlDataSource id="States" runat="server" ConnectionString="<%$ ConnectionStrings:ECMApp3 %>" SelectCommand="select distinct state from weather_Station order by state"
/>
<
table id="TableSensor" cellspacing="2" cellpadding="1" width="400px" border="1" rules="none"
style="BORDER-COLLAPSE: collapse">
<tr>
<td> <asp:Label Text="Project_id :" runat="server" ID="Label1" CssClass="style1" />
</td>
<td>
<asp:DropDownList ID="DropDownListprojects" runat="server"
DataSourceID="LProjectsSource" DataTextField="Name"
DataValueField="project_id" Width="250px" >
</asp:DropDownList>
</td>
<td> </td>
<td>
</td>
</tr>
<tr>
<td> <asp:Label Text="Name :" runat="server" ID="Label3" CssClass="style1" />
</td>
<td>
<asp:TextBox ID="Name" runat="server"
Text='<%# DataBinder.Eval( Container, "DataItem.name" ) %>'></asp:TextBox>
</td>
<td> </td>
<td>
</td>
</tr>
<tr>
<td> <asp:Label Text="State:" runat="server" ID="Label5" CssClass="style1" />
</td>
<td>
<asp:DropDownList ID="StateDropDownList" runat="server"
DataSourceID="States" DataTextField="state" DataValueField="state"
Width="150px" onselectedindexchanged="StateDropDown_SelectedIndexChanged" >
</asp:DropDownList>
</td>
<td> </td>
<td>
</td>
</tr>
<tr>
<td class="style2"> <asp:Label Text="WeatherStation:" runat="server" ID="Label7"
CssClass="style1" />
</td>
<td class="style2">
<asp:DropDownList ID="DropDownListweatherStations" runat="server"
DataSourceID="WeatherStationSource" DataTextField="station_name"
DataValueField="id" Width="250px" >
</asp:DropDownList>
</td>
<td class="style2"> </td>
<td class="style2">
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:button id="btnUpdate" text="Update" runat="server" CommandName="Update" Visible='<%# !(DataItem is Telerik.Web.UI.GridInsertionObject) %>'></asp:button>
<asp:button id="btnInsert" text="Insert" runat="server" CommandName="PerformInsert" Visible='<%# DataItem is Telerik.Web.UI.GridInsertionObject %>'></asp:button>
<asp:button id="btnCancel" text="Cancel" runat="server" causesvalidation="False" commandname="Cancel"></asp:button></td>
</tr>
<tr>
<td align="right" colspan="2">
</td>
</tr>
</
table>