ComboBoxDataSourceID.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
ComboBox1.DataSourceID = "XmlDataSource1";
ComboBox1.DataTextField = "Name";
ComboBox1.DataValueField = "ID";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Ajax ComboBox - How to set change ComboBox DataSourceID programmatically in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
ASP.NET Ajax ComboBox - How to set change ComboBox
<br /> DataSourceID programmatically in asp.net
</h2>
<hr width="550" align="left" color="LightBlue" />
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<br /><br />
<asp:ComboBox
ID="ComboBox1"
runat="server"
DropDownStyle="DropDown"
AutoCompleteMode="None"
CaseSensitive="false"
RenderMode="Block"
AppendDataBoundItems="false"
AutoPostBack="false"
Font-Names="Comic Sans MS"
Font-Size="Medium"
ForeColor="DeepPink"
>
</asp:ComboBox>
<asp:XmlDataSource ID="XmlDataSource1" runat="server">
<Data>
<Colors>
<Color ID="1" Name="Indigo" />
<Color ID="2" Name="DarkGoldenRod" />
<Color ID="3" Name="BlanchedAlmond" />
<Color ID="4" Name="DarkGrey" />
<Color ID="5" Name="FireBrick" />
</Colors>
</Data>
</asp:XmlDataSource>
<br /><br /><br />
<br /><br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Set ComboBox DataSourceID: 'XmlDataSource1'"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>
No comments:
Post a Comment