tags:

views:

15

answers:

1

Hello Experts!! I am a learner and i have a problem data binding the dataset. Please review my code and tell me where i am doing wrong. It does not bind and hence throws an exception "Both DataSource and DataSourceID are defined on 'getGridmerchantLocationData'. Remove one definition"

       <asp:ObjectDataSource ID="getGridMerchantLocationData" runat="server" 
       OldValuesParameterFormatString="original_{0}" 
       SelectMethod="GetLocations" TypeName="string">            
       </asp:ObjectDataSource>

Code Behind


protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.filllocation(ApplicationData.VAL_DEFAULT_SORT_LOCATION, ApplicationData.VAL_ASC); } }

public void BindData()
{ 


}
private void filllocation(string orderby, string order)
{
    DataSet ds = new BusinessLogic.BLL.Merchant2().getGridMerchantLocationData(CommonHelper.GetLoggedInMerchant(), orderby, order);
    if (ds != null && ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
    {
        diableloc.DataSource = ds;
        diableloc.DataBind();
    }
    else
    {
        ds = null;
        diableloc.DataSource = ds;
        diableloc.DataBind();
    }

getGridMerchantLocationData has many columns but i just need one column out of it and bind it to the gridview. Please someone help me out! Thanks!!

+1  A: 

Yes you cannot define the ObjectDataSource as being the datasource for your 'diableloc' control and in code assign the DataSource to 'ds' as well. You can only have one datasource for a control.

atconway
Sir, Could you please elaborate and tell me bit more clearly!! I appreciate all your help. Thanks!
Ram
I'm not sure how much more clear we (and the error) can get. In the declaration of the diableloc control, remove the DataSourceID section. You are manually assigning the DataSource in the code behind, so you don't need to also assign the DataSourceID in the aspx page.
Jason Berkan
You guys are awesome!! Purely Experts! Thanks!
Ram