Instead of writing below three lines how can I declare them in 1 line?
Label sub1 = (Label) GridView1.Rows[0].FindControl("Label5");
Label sub2 = (Label) GridView1.Rows[1].FindControl("Label5");
Label sub3 = (Label) GridView1.Rows[2].FindControl("Label5");
"0"또는 "1"0r "2"대신 "i"를 입력하면 "2"값만 표시됩니다. 그래서 모든 방법을 한 줄로 작성하는 것이 좋습니까?레이블을 한 줄로 선언하는 방법은 무엇입니까?
The code is:
for (int i = 0; i < ds.Rows.Count; i++) {
Label price = (Label) GridView1.Rows[i].FindControl("Label5");
TextBox ttlqnt = (TextBox) GridView1.Rows[i].FindControl("TextBox1");
decimal y = decimal.Parse(ttlqnt.Text);
Label pricecal = (Label) GridView1.Rows[i].FindControl("Label2");
decimal z = (y * decimal.Parse(price.Text));
pricecal.Text = "Rs." + (z.ToString());
Label sub1 = (Label) GridView1.Rows[0].FindControl("Label5");
Label sub2 = (Label) GridView1.Rows[1].FindControl("Label5");
Label sub3 = (Label) GridView1.Rows[2].FindControl("Label5");
TextBox ttlqnt1 = (TextBox) GridView1.Rows[0].FindControl("TextBox1");
TextBox ttlqnt2 = (TextBox) GridView1.Rows[1].FindControl("TextBox1");
TextBox ttlqnt3 = (TextBox) GridView1.Rows[2].FindControl("TextBox1");
decimal c1 = decimal.Parse(ttlqnt1.Text);
decimal c2 = decimal.Parse(ttlqnt2.Text);
decimal c3 = decimal.Parse(ttlqnt3.Text);
decimal y1 = c1 * decimal.Parse(sub1.Text);
decimal y2 = c2 * decimal.Parse(sub2.Text);
decimal y3 = c3 * decimal.Parse(sub3.Text);
decimal y4 = y1 + y2 + y3;
Subtotal.Text = y4.ToString();
}
원하는 이유가 궁금합니다. 코드는 반복문이 없어도 읽을 수 있습니다. 당연히 행 수가 동적 인 경우가 아니면. –
행 값 (예 : 0/1/2)이 없을 때 오류가 표시되기 때문에 수정하고 싶습니다. – Swadesh