Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
protected void GV_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
        Label lblMaterial = (Label)e.Row.FindControl("lblMaterial");
        Label lblMaterialValue = (Label)e.Row.FindControl("LblMaterialValue");
        Label lblMaterialQty = (Label)e.Row.FindControl("lblMaterialQty");
 
        DataTable dt = (DataTable)Session["dt"];
        
        if (dt.Rows.Count == 0)
        {
                
        }
        else
        {
          //here i do wrong     
           for (int i = 0; i < dt.Rows.Count; i++)
           {
               lblMaterial.Text = dt.Rows[i][1].ToString();
               lblMaterialValue.Text = dt.Rows[i][0].ToString();
               lblMaterialQty.Text = dt.Rows[i][2].ToString();
           }        }
    }
}
        
 
In my DataTable I have a 4 Rows butin my Grid it's Display Last Row only how to display all the rows can anyone help me ...
 

Thanks in Advance....
Posted 27-Sep-12 23:16pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Because u r using loop that is why every time your labels value r replaced by next one so at the last of loop , it contain only values of last row 
for (int i = 0; i < dt.Rows.Count; i++)
          {
              lblMaterial.Text = dt.Rows[i][1].ToString();
              lblMaterialValue.Text = dt.Rows[i][0].ToString();
              lblMaterialQty.Text = dt.Rows[i][2].ToString();
          }
 
tell what do u want ?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi pranathis012,
i think you are doing wrong. On RowdataBound event of gridview, You can only modify or change the already bind data on run time. i.e. if you want to do anything with rows of gridview on conditional basis like row formatting or any-thing.. so you can do. You should bind data table to Gridview using property
 
<pre lang="c#">
GridViewObject.DataSource=datatableObject;  
and after binding you can change or modify with data.
 

Regards Rahul
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 725
1 OriginalGriff 385
2 CPallini 240
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,835
1 Sergey Alexandrovich Kryukov 5,198
2 CPallini 4,740
3 George Jonsson 3,167
4 Gihan Liyanage 2,470


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100