A multiple records to GridView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flashleo
    New Member
    • Apr 2009
    • 4

    A multiple records to GridView

    Code:
    string imgg=1,3,4,9,18,
    
    imgg=imgg.TrimEnd(',');
                    string[] words = imgg.Split(',');
                    foreach (string word in words)
                    {
                       strrr = "select * from profiles where proid=" + int.Parse(word);
                        SqlDataSource2.SelectCommand = strrr;
                        GridView2.DataSourceID = "sqldatasource2";
                         GridView2.DataBind();
    }
    I am trying to add data to gridview in a loop with comma separated string. But everytime gridview remove previous data and bind only with last id. Please help i want to plus record in gridview with every loop.
    Last edited by Frinavale; Dec 3 '09, 03:27 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • semomaniz
    Recognized Expert New Member
    • Oct 2007
    • 210

    #2
    you are binding the gridview inside a for loop which is why all your previous data is being removed and the only data being displayed is the last id. What i would suggest is create a data table and store all the results returned from the sql statement. Then outside your for loop bind the data table to your gridview.

    I hope this helps

    Comment

    Working...