這裡的資料一律是假造的!
選取 | 星系 | 註記 |
Aries | ||
Gimini | ||
Leon | ||
Libra |
星系 | 特質 | 註記 |
Aries | 暴躁 | 80% |
Aries | 非常好騙 | 80% |
Gimini | 人格分裂 | 90% |
Gimini | 不可思議 | 90% |
一開始要用Gridview做出來....直接進程式碼!
以下直接複製到div裡面就可以用...
不要太介意名字,開心就好
<asp:GridView ID="gvData" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField HeaderText="選取">
<ItemTemplate>
<asp:CheckBox ID="cbxSign" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RType" HeaderText="星系" />
<asp:TemplateField HeaderText="註記">
<ItemTemplate>
<asp:TextBox ID="tbxDate" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="btnNew" runat="server" Text="產生" OnClick="btnNew_Click" />
<asp:GridView ID="gvView" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="RType" HeaderText="星系" />
<asp:BoundField DataField="EmpNo" HeaderText="特質" />
<asp:BoundField DataField="EndDate" HeaderText="註記" />
</Columns>
</asp:GridView>
後台長這樣,Page_Load要蓋掉喔~
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();//綁Gridview的資料
}
}
private void BindData()
{
gvData.DataSource = GenerateDataTableRev();
gvData.DataBind();
}
//角色對應特質的假資料
private DataTable RoleEmpMap()
{
DataTable dtr = new DataTable();
dtr.Columns.Add("RType");
dtr.Columns.Add("Emp");
dtr.Rows.Add(new object[] { "Aries", "暴躁" });
dtr.Rows.Add(new object[] { "Aries", "非常好騙" });
dtr.Rows.Add(new object[] { "Gimini", "人格分裂" });
dtr.Rows.Add(new object[] { "Gimini", "不可思議" });
dtr.Rows.Add(new object[] { "Leon", "驕傲" });
dtr.Rows.Add(new object[] { "Libra", "蛤?" });
return dtr;
}
//最後要呈現的資料格式(這是空的DataTable)
private DataTable KeyInfo()
{
DataTable dtr = new DataTable();
dtr.Columns.Add("RType");
dtr.Columns.Add("EmpNo");
dtr.Columns.Add("EndDate");
return dtr;
}
//塞原始GridView假資料
private DataTable GenerateDataTableRev()
{
DataTable dtr = new DataTable();
dtr.Columns.Add("RType");
dtr.Rows.Add(new object[] { "Aries" });
dtr.Rows.Add(new object[] { "Gimini" });
dtr.Rows.Add(new object[] { "Leon" });
dtr.Rows.Add(new object[] { "Libra" });
return dtr;
}
protected void btnNew_Click(object sender, EventArgs e)
{
DataTable dt = KeyInfo();
DataTable dtMap = RoleEmpMap();
DataTable dtMapResult = KeyInfo();
for (int i = 0; i < gvData.Rows.Count; i++)
{
CheckBox cbx = gvData.Rows[i].FindControl("cbxSign") as CheckBox;
TextBox tbx = gvData.Rows[i].FindControl("tbxDate") as TextBox;
if (cbx.Checked)
{
dt.Rows.Add(gvData.Rows[i].Cells[1].Text, tbx.Text);
}
}
//把TextBox的字傳一份到目標Datatable裡
for (int j = 0; j < dt.Rows.Count; j++)
{
for (int k = 0; k < dtMap.Rows.Count; k++)
{
DataRow dr = dtMap.Rows[k];
if (dt.Rows[j][0].Equals(dtMap.Rows[k][0]))
{
dtMapResult.Rows.Add(dtMap.Rows[k][0], dtMap.Rows[k][1],dt.Rows[j][1]);
}
}
}
gvView.DataSource = dtMapResult;
gvView.DataBind();
}
完整的功能實踐如以上~
可以點點看產生但是不會有作用的哈哈哈(廢話
為了避免日後的我看不懂所以每一篇我都要寫得很好用= =
沒有留言:
張貼留言