Update DataSource

2 posts, 0 answers
  1. Deivison Julio
    Deivison Julio avatar
    3 posts
    Member since:
    Feb 2012

    Posted 17 Apr 2012 Link to this post

    How do I update a datasource for a listbox via code by clicking on a button? Something like ListBox.DataSource.Update (), Listbox.ResetBind (), do not know ... 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Apr 2012 Link to this post

    Hi Deivison Julio,

    You can use DataBind method while binding at Runtime as follows.

    ASPX:
    <telerik:RadListBox ID="RadListBox1" runat="server">
    </telerik:RadListBox>
    <asp:Button ID="Button1"  runat="server" onclick="Button1_Click" />
    <asp:SqlDataSource ID="SqlDataSource2" runat="server"  SelectCommand="SELECT EmployeeID FROM [Employees]" ConnectionString= "<%$ ConnectionStrings:NorthwindConnectionString %>">
    </asp:SqlDataSource>

    C#:
    protected void Button1_Click(object sender, EventArgs e)
       {
           RadListBox1.DataSourceID = "SqlDataSource1";
           RadListBox1.DataTextField = "EmployeeID";
           RadListBox1.DataValueField = "EmployeeID";
           RadListBox1.DataBind();
       }

    For more information please take a look into this.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top