0

I have a infragistics grid with auto generated columns how can i assign a strored proc result to it from code behind

      <ig:WebScriptManager ID="WebScriptManager1" runat="server"></ig:WebScriptManager>
<ig:WebDataGrid ID="EntityGrid" runat="server"  Width="100%">
    <Behaviors>
        <ig:Sorting>
        </ig:Sorting>
    </Behaviors>
</ig:WebDataGrid>

code behind is

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        EntityName.Text = DropDownList1.SelectedItem.Text;
        string @RegardingObjectName = DropDownList1.SelectedItem.Text.Trim();
        String strConnString = ConfigurationManager.ConnectionStrings["LiveLeaseConnectionString"].ConnectionString;
        SqlConnection con = new SqlConnection(strConnString);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "p_DataList_ByRegardingObject";
        cmd.Parameters.AddWithValue("@RegardingObjectName", @RegardingObjectName);
        cmd.Connection = con;
        try
        {              
            con.Open();
            EntityGrid.DataSource = cmd.ExecuteReader();
            EntityGrid.DataBind();

i need to passin entity as parameter to stored proc. how can i do that here?

i am getting reader closed error

user2167089
  • 151
  • 6
  • 20

1 Answers1

1

You will need to add a ControlParameter to SelectParameters

<asp:ControlParameter Name="entityId" 
ControlID="DropDownList1" 
PropertyName="SelectedItem" Type="String" />

Also see this question How to specify parameter value for stored procedure in SqlDataSource

Edit you can use the Selecting event as shown here

Writing a SQLdatasource in code behind in C# to use a code behind value

You can also add a select parameter as

EntityGrid.SelectParameters.Add("entityId", DropDownList1.SelectedItem.Text);

Just rename "entityId" to the name of parameter to be used with SP

Edit2 :

Instead of

EntityGrid.DataSource = cmd.ExecuteReader();
            EntityGrid.DataBind();

Try this

SqlDataReader reader = cmd.ExecuteReader();
    using (reader)
    {
      DataTable table = new DataTable();
      table.Load(reader);
      EntityGrid.DataSource = table;
    }

See this link for more :
http://mentaljetsam.wordpress.com/2008/11/20/loading-an-sqldatareader-into-a-datagridview/

Community
  • 1
  • 1
Amitd
  • 4,769
  • 8
  • 56
  • 82