Skip to main content
Tab

ASPxListEdit.DataSourceID Property

Specifies the ID of the data source control from which the editor gets data items.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v22.1.dll

Declaration

public override string DataSourceID { get; set; }

Property Value

Type Description
String

The ID of the data source control.

Remarks

This property is a wrapper of the ListEditProperties.DataSourceID property.

Design Time

  1. Add ASPxListBox to the form.

  2. In design mode, invoke the control’s smart tag menu and select the <New data source…> command.

    HowTo-NewDataSource

  3. Choose a data source type and configure its options:

    • Specify the fields that you want to display in the ASPxListBox control.

    • Click Advanced… and select the Generate INSERT, UPDATE, and DELETE statements check box to edit your data source in the web application.

    • Click Test Query to preview the selected data.

    ASPxComboBox - SelectColumns

  4. Specify the ASPxListBox.TextField and ASPxListBox.ValueField properties.

The resulting code:

<form id="form1" runat="server">
  <dx:ASPxListBox ID="ASPxListBox1" runat="server" DataSourceID="SqlDataSource1" TextField="ShipCountry" ValueField="OrderID">
  </dx:ASPxListBox>
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    DeleteCommand="DELETE FROM [Orders] WHERE [OrderID] = @OrderID"
    InsertCommand="INSERT INTO [Orders] ([ShipCountry]) VALUES (@ShipCountry)"
    SelectCommand="SELECT [OrderID], [ShipCountry] FROM [Orders]"
    UpdateCommand="UPDATE [Orders] SET [ShipCountry] = @ShipCountry WHERE [OrderID] = @OrderID" >
    <DeleteParameters>
      <asp:Parameter Name="OrderID" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
      <asp:Parameter Name="ShipCountry" Type="String" />
    </InsertParameters>
    <UpdateParameters>
      <asp:Parameter Name="ShipCountry" Type="String" />
      <asp:Parameter Name="OrderID" Type="Int32" />
    </UpdateParameters>
  </asp:SqlDataSource>
</form>

Runtime

  1. Create an instance of the ASPxListBox object, specify its ID, and add this object to the form.

  2. Create a connection to the data source file.

  3. Specify the ASPxListBox.DataSource, ASPxListBox.TextField, and ASPxListBox.ValueField properties.

  4. Call the DataBindItems method to bind the control to the specified data source.

The resulting code:

protected void Page_Load(object sender, EventArgs e){
    ASPxListBox lb = new ASPxListBox();
    lb.ID = "Cities";
    form1.Controls.Add(lb);

    SqlDataSource ds = new SqlDataSource(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\NWind.mdf;Integrated Security=True", "SELECT [City] FROM [Customers]");

    ds.ProviderName = "System.Data.SqlClient";
    ds.ID = "ds";
    form1.Controls.Add(ds);
    lb.DataSourceID = "ds";
    lb.TextField = "City";
    lb.ValueField = "City";
    lb.DataBindItems();
}
See Also