Re: [問題] 一筆東西有分SIZE,如何寫..
我來提供個蠢方法好了
之前有個前輩告訴我不知道該從何下手就用literal的tag來塞html碼進去吧!
: ┌---------┐
: |肉燥飯 |大 |50元|
: ├---------┤
: |肉燥飯 |中 |40元|
: ├---------┤
: |肉燥飯 |小 |30元|
: ├---------┤
: |魯肉飯 |大 |50元|
: ├---------┤
: |魯肉飯 |中 |40元|
: ├---------┤
: |魯肉飯 |小 |30元|
: └---------┘
首先在aspx放個沒有內容的literal 假設它叫Literal1好了
: ┌---------------┐
: |肉燥飯 |大50元 中40元 小30元|
: ├---------------┤
: |肉燥飯 |大50元 中40元 小30元|
: └---------------┘
假設你的table叫menu
共有meal 食物,size 大小, price 價錢 三欄
我試著用behind code來塞資料
做成這樣感覺大概像這個
//連線
SqlConnection conn = new SqlConnection(conString);
conn.Open();
//SQL碼
string menuSql="select meal,size,price from menu"
+"order by meal,price desc"
SqlCommand Cmmd = new SqlCommand(menuSql, conn);
SqlDataReader sr = Cmmd.ExecuteReader();
DataTable dt = new DataTable();
//讀進DataTable
dt.Load(sr);
//在literal塞table進去
Literal1.Text += "<table>";
//從頭讀一次DataTable找出食物來
for (int i = 0; i < dt.Rows.Count; i++)
{
//table的row
Literal1.Text += "<tr>";
//第一個cell
Literal1.Text += "<td>";
//第i行的第零個欄位 照選法會是食物
Literal1.Text += dt.Rows[i][0].ToString();
Literal1.Text += "</td> ";
//第二個cell
Literal1.Text += "<td>";
//做巢狀迴圈
for (int j = 0; j < dt.Rows.Count; j++)
{
//當重新讀到j的食物等於原來i的食物就開始把大小跟價錢放進去
if (dt.Rows[i][0].ToString() == dt.Rows[j][0].ToString())
{
Literal1.Text += dt.Rows[j][1].ToString() //大小
+ " " //空格
+ dt.Rows[j][2].ToString() //價錢
+" "; //又是空格
//就算你有2000種大小他都會放到同樣的這個cell裡面
}
}
Literal1.Text += "</td>";
Literal1.Text += "</tr>";
}
Literal1.Text += "</table>"; //結束這個table
應該是沒問題才對
不過table完全沒有樣式
自己要再手動加進去就是了
因為小弟對template不熟之前工作也都常常是這樣塞
太蠢還請各位大大嘲笑小力一點
還有啊...有沒有template速成的參考資料啊XD
--
不廢話! 奮鬥吧! 成為獨當一面的.net工程師!
http://ansagazx.blogspot.tw/
By 患有嚴重廢話病的工程師
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.32.144.249
※ 編輯: Ansaga 來自: 114.32.144.249 (11/05 23:44)
推
11/05 23:56, , 1F
11/05 23:56, 1F
→
11/06 11:20, , 2F
11/06 11:20, 2F
推
11/07 10:52, , 3F
11/07 10:52, 3F
→
11/07 10:53, , 4F
11/07 10:53, 4F
→
11/07 13:25, , 5F
11/07 13:25, 5F
推
11/08 12:39, , 6F
11/08 12:39, 6F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):