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
622
Binding datatable data to a column using C# code.
posted

Hi All,

I need to display data from a datatable to a specific column in the grid. The scenario is :

I have addded 5 columsn to grid using c# code: 

ugbProduct.Columns.Add("column1", "column1");

The datatable contains 10 columns and need display only 5 columns. In this situation how to bind 5 datatable columns to the 5 columns in the grid using code?

can this be done from the design time also ?

Regards,

Abhi

 

 

Parents
  • 28464
    Verified Answer
    posted

    Hello Abhi, 

    Thanks for writing. I believe the key here is to set the AutoGenerateColumns property of your UltraWebGrid.DisplayLayout to False. This way, the grid will not try to automatically pick and display all 10 columns from your datasource, but only the columns you have defined.

    <igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server">
            <displaylayout  AutoGenerateColumns="false" ... />
    </igtbl:UltrawebGrid>

    You can definitely use the designer in VS.NET to pick the columns you want to display, once you have set AutoGenerateColumns to False, or you can use code-behind (like you've suggested in your post) - I believe the following online KB article is very useful and can easily get you started. You can also review all DevCenter grid articles - there are tons of useful resources there.

    HOWTO:Creating a WebGrid Programmatically 

    http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.Aspx?ArticleID=3430

    Hope this helps. 

Reply Children
No Data