title: C# ASP How can i change the dataSouce ID of a datalist
body: <p>How can i change the Datalist DatasourceID?</p>
  
  <p>I am using c# with a ASP datalist bound to a datasource with DataSourceId="DataSource1"</p>
  
  <p>I have an OnCommandclick event with the following code:</p>
  
  <pre><code>    protected void DataList4_ItemCommand(object source, DataListCommandEventArgs e)
      {
          DateTime sessionExpiry;
          string getCompany, strCompany, getUser = GetID.userSession();
          Label myLabel = (Label)e.Item.FindControl("EpicLabel");
          string strEpic = myLabel.Text;
          sessionExpiry = DateTime.MinValue;
          strCompany = GetData.companyName(strEpic);
          SetItem.cookie("SetAddEpic", strEpic, sessionExpiry);
  
          switch (e.CommandName)
          {
              case "RatingWatchList":
                  if (getUser != "0")
                  {
                      SetItem.cookie("SetAddEpic", strEpic, sessionExpiry);
                      SetItem.cookie("SetAddCompany", strCompany, sessionExpiry);
                      ScriptManager.RegisterStartupScript(Page, GetType(), "JsStatus", 
                                   "AddWatchListItem();", true);
                  }
                  else { ScriptManager.RegisterStartupScript(Page, GetType(), 
                      "JsStatus", "errorMessage('Please log in to use this 
                                                function!');", true); }
                  break;
  
              case "RatingAddAlert":
                  if (getUser != "0")
                  {
                      SetItem.cookie("SetAddCompany", strCompany, sessionExpiry);
                      ScriptManager.RegisterStartupScript(Page, GetType(), "JsStatus", 
                                                      "AddAlert();", true);
                  }
                  else { ScriptManager.RegisterStartupScript(Page, GetType(), 
                        "JsStatus",   
                        "errorMessage('Please log in to use this function!');", true); }
                  break;
          }
      }
  </code></pre>
  
  <p>but i need to change the datasource without removing the DataSourceID from the ASP datalist so i cannot use c# </p>
  
  <pre><code> DataList1.datasource="NewQuery";
   DataList1.DataBind(); 
  </code></pre>
  
  <p>because the command buttons do not work when you remove the DataSourceID.</p>