webForumDet fria alternativet

Kortare kod

.NET

1 svar · 172 visningar · startad av aleborg

Medlem sedan jan. 20013 341 inlägg
Frågan#1

Har den här koden:

foreach(Control tbl in contact_ctrl.Rows) 
{ 
	foreach(Control row in tbl.Controls) 
	{ 
		foreach(Control cell in row.Controls) 
		{ 
			if(cell.GetType().ToString()=="System.Web.UI.HtmlControls.HtmlInputText")
				Response.Write(cell.ID + " = "+ ((HtmlInputText)cell.FindControl(cell.ID)).Value + "<br>");
		}
	}
}
foreach(Control tbl in admin_ctrl.Rows) 
{ 
	foreach(Control row in tbl.Controls) 
	{ 
		foreach(Control cell in row.Controls) 
		{ 
			if(cell.GetType().ToString()=="System.Web.UI.HtmlControls.HtmlInputText")
				Response.Write(cell.ID + " = "+ ((HtmlInputText)cell.FindControl(cell.ID)).Value + "<br>");
		}
	}
}
foreach(Control tbl in tech_ctrl.Rows) 
{ 
	foreach(Control row in tbl.Controls) 
	{ 
		foreach(Control cell in row.Controls) 
		{ 
			if(cell.GetType().ToString()=="System.Web.UI.HtmlControls.HtmlInputText")
				Response.Write(cell.ID + " = "+ ((HtmlInputText)cell.FindControl(cell.ID)).Value + "<br>");
		}
	}
}
foreach(Control tbl in billing_ctrl.Rows) 
{ 
	foreach(Control row in tbl.Controls) 
	{ 
		foreach(Control cell in row.Controls) 
		{ 
			if(cell.GetType().ToString()=="System.Web.UI.HtmlControls.HtmlInputText")
				Response.Write(cell.ID + " = "+ ((HtmlInputText)cell.FindControl(cell.ID)).Value + "<br>");
		}
	}
}

Hur kan man korta ner den?

Medlem sedan sep. 20011 914 inlägg
#2

Detta borde väl funka. Lägg in dina tables(antar att det är tabels) i hmm arrayen.

void lalala(){
   Table[] hmm = {new Table(),new Table(),new Table(), new Table(),new Table()};
   grr(hmm);
}

void grr(Table[] hmm){
   for(int i = 0; i < hmm.Length; i++){
      foreach(Control tbl in hmm[i].Rows) 
      { 
         foreach(Control row in tbl.Controls) 
         { 
            foreach(Control cell in row.Controls) 
            { 
               if(cell.GetType().ToString()=="System.Web.UI.HtmlControls.HtmlInputText")
               Response.Write(cell.ID + " = "+ ((HtmlInputText)cell.FindControl(cell.ID)).Value + "<br>");
            }
         }
      }
   }
}
262 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
124 ms — deklarationer (db)
0 ms — hämta statistik (cache)
133 ms — hämta tråd, inlägg och bilagor (db)
125 ms — ändringar (db)