get other values from source on selected index changed of combo box
I believe it's irrelevant of what type of combo box i'm using, but I'm using a Rad Combo Box. My data source not only selects data for the Data Text Field and Value Field but it also selects a couple of other columns. I want to get the values of those columns for the selected Item. How can i accomplish this on selectedindexchanged?
<table width="100%">
<tr>开发者_如何学编程
<td align="center" ><strong>Please select a policy :</strong>
<telerik:RadComboBox ID="RadComboPolicy" runat="server" Width="400px" OnSelectedIndexChanged="RadComboPolicy_SelectedIndexChanged" DataSourceID="SqlDataSource2" AppendDataBoundItems="true" DataTextField="Pname" AutoPostBack="true" DataValueField="PID">
<Items>
<telerik:RadComboBoxItem runat="server" Selected="true" Value="-1" Text="Select a Policy to Begin" />
</Items>
</telerik:RadComboBox>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ConnectionString %>" SelectCommand="select p.pid,p.pname,p.startdate,p.enddate from insurance..policy p">
</asp:SqlDataSource>
</td>
</tr>
</table>
protected void RadComboPolicy_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
//Here i want to get the startdate and enddate
}
As your code stands right now, you're basically throwing out the startdate
and enddate
data when you bind pid
and pname
to the combo box. You'll either need to store this data in a hidden field (as statichippo stated) or pull the information out of the database using the pid
on the server-side.
In any case, as it stands now, this data isn't available anywhere during the post-back.
You need to put the data somewhere. This could be a hidden field (like a literal with display=false). Then you can get the RadComboItem's row and find the hidden fields and parse the dates out of there.
精彩评论