Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
dynamic webdata grid not updating header
posted

I have a data grid that gets data dynamically from a stored proc. depending on the selection in drop down the grid should update with relevant data. the data part is working but the headers wont change when i change my selection. how can i achieve this? and also i want to hide a column on this dynamic grid.

here is the code in aspx

<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Select Entity</asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" ID="EntityName"></asp:Label>
<ig:WebScriptManager ID="WebScriptManager1" runat="server"></ig:WebScriptManager>
<ig:WebDataGrid ID="EntityGrid" runat="server" Width="100%" Height="50%" StyleSetName="Claymation" >
<Columns>

</Columns>
<Behaviors>
<ig:Sorting>
</ig:Sorting>

</Behaviors>
<ClientEvents Click="NavigateOnClick" />

</ig:WebDataGrid>

and code behind

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.EntityGrid.DataSource = null;
this.EntityGrid.DataBind();
EntityName.Text = DropDownList1.SelectedItem.Text;
string entity = "t_" + DropDownList1.SelectedItem.Text;
String strConnString = ConfigurationManager.ConnectionStrings["LiveLeaseConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("p_DataList_ByRegardingObject", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@RegardingObjectName", entity);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
this.EntityGrid.DataSource = ds;
this.EntityGrid.DataBind();

Parents
No Data
Reply
  • 500
    Verified Answer
    posted

    Hi Jahnavi,

    You have to call the following statement before assigning the new data source to the grid.

    this.EntityGrid.ClearDataSource();

    I would recommend you use client side column hiding, because the grid columns are created at a later moment and you don't have access to them on the server.

    I have attached a sample web site that demonstrates both column hiding and setting different data sources with different columns. Please, feel free to ask for some additional information if needed. I hope this solution helps.

    Thanks,

    WebSite11.zip
Children