c# - How to add header columns based on data fetch from the database in gridview -


i have gridview , want make headers dynamically based on sql query like...

select question quiz quizid 123. 

this query return * number of questions based on quizid.

how create headers data that's been selected database?

you can use datatable this.

i don't know technologies used database management, used linq sql. , following sample:

dataclassesdatacontext db = new dataclassesdatacontext();  protected datatable getdatasource()  {     datatable dt = new datatable();      var questions = db.executequery<string>("select question quiz quizid 123").tolist();      // header implementation     int count = 0;     foreach (var question in questions)     {         datacolumn dc = new datacolumn(question);         dt.columns.add(dc);         count++;     }      // rows implementation here     datarow row = dt.newrow();     ...     dt.rows.add(row);      return dt; }   protected void page_load(object sender, eventargs e) {     gridview1.datasource = getdatasource();     gridview1.databind(); } 

and here aspx code:

<asp:gridview id="gridview1" runat="server"></asp:gridview> 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -