GridView (Binded to ObjectDataSource) not displaying fields in the selected fields zone in Fields Dialog

StackOverflow https://stackoverflow.com/questions/12386412

سؤال

I have a Gridview that I bind to an ObjectDataSoure.

The ObjectDataSource uses a business object that calls a DAL method that returns DataTable with the query results.

Application works at run time ,But at design time there is a problem: When I use the GridView's Tasks Wizard -> Edit Columns : No fields appear in the Selected fields text area(So I can't use the wizard to edit the columns).

DAL methods:

public override DataTable GetAllWorkers()
    {
        using (SqlConnection con = new SqlConnection(this.ConnectionString)) {
            SqlCommand cmd = new SqlCommand("t_Workers_GetAllWorkers", con);
            cmd.CommandType = CommandType.StoredProcedure;
            con.Open();
            return GetTable(cmd);
        } 

    }

    private DataTable GetTable(SqlCommand cmd)
    {

        SqlDataAdapter adp = new SqlDataAdapter();
        adp.SelectCommand = cmd;
        DataTable dt = new DataTable();
        adp.Fill(dt);
        return dt;

    }

BLL Method :

public static DataTable GetAllWorkers()
    {
        return DataProvider.Instance().GetAllWorkers();
    }

ASPX web page :

       <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
        SelectMethod="GetAllWorkers" TypeName="BLL.BizImpl"></asp:ObjectDataSource>

    <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" 
        EnableModelValidation="True" Height="156px" Width="270px">
    </asp:GridView>

Can someone please explain what is the cause for the problem ?

   Thanks
هل كانت مفيدة؟

المحلول

It seems that because you do not specifically declare your columns in your aspx Page you won't be able to see them in Wizard. At the moment your GridView is populated with data because the

AutoGenerateColumns

property defaults to true. You can turn the to false and define the columns yourself. You then have more control over what you want to display in them etc.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top