Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Label lbl2 = e.Row.FindControl("lblName") as Label;
Label lbl3 = e.Row.FindControl("lblKeyword") as Label;
Label lbl4 = e.Row.FindControl("lblKey") as Label;



C#
foreach (GridViewRow rows in gvRules.Rows)
             {


                 lbl1.Text + "If" + lbl3.Text + "then Action " + lbl2.Text +;


             }



i want to add the labels in in for each condition..i want this as like a sentence while bind grid ..plz sahre ur idea
Posted

1 solution

MIDL
string addAll="";
foreach (GridViewRow rows in gvRules.Rows)
{
  addAll += lbl2.Text + "If" + lbl3.Text + "then Action " + lbl2.Text ;
}
//addAll contains all the appended text which you can display.


You can also use string Builder[^]
 
Share this answer
 
Comments
suryaswathi 15-Jul-11 2:34am    
hi thanks its works but i want to display the string in a grid view itself..how to display
m@dhu 15-Jul-11 2:45am    
You can display in a label in rowdatabound/rowcommand event according to your requirement. Assign the value of addAll to a label in the gridview.
suryaswathi 15-Jul-11 2:50am    
hi sir

Label addall = e.Row.FindControl(" lbladdall") as Label; //i created one label

string addAll = "";

int i = 1;
foreach (GridViewRow rows in gvRules.Rows)
{


addAll = lbl1.Text + "If" + lbl3.Text + lbl5.Text + lbl6.Text + "then Action " + lbl2.Text;

i++;


}
addAll = addall.Text;
for that label i assing the string but its getting error
m@dhu 15-Jul-11 2:58am    
This should be addall.Text = addAll; at the end.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900