I am using Sqldatasource for Gridview. I want to change the datasource at runtime how to do it please help me.
I give the following command at design page
<asp:GridView ID="GridView2" OnRowDataBound="GridView2_RowDataBound" DataSourceID="SqlDataSource1" runat="server" align="center" AutoGenerateColumns="False"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Vertical" Height="161px" Width="837px">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
And I want to Change the datasource select command for below code
SqlCommand sqlcmd = new SqlCommand("FETCH_COUNTER_UMAP_SP",connect.cn());
sqlcmd.Parameters.AddWithValue("@COMPANYCODE", company_name);
sqlcmd.Parameters.AddWithValue("@BRANCHCODE", s);
sqlcmd.Parameters.AddWithValue("@USERID", uname);
sqlcmd.Parameters.AddWithValue("@FINYEAR", Finyear);
sqlcmd.Parameters.AddWithValue("@ERRORID", 1);
sqlcmd.Parameters.AddWithValue("@MAPUSERID", cmbusers.SelectedValue);
sqlcmd.CommandType = CommandType.StoredProcedure;
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
da.Fill(dt);
SqlDataSource1.SelectCommand = dt;
SqlDataSource1.DataBind();
But it is display Error how do it please help me