绑定order表后(图一)
------------------
| id | 姓名 | 业务总成绩 | |
------------------
| 1 | 小张 | 100000 |详细 |
------------------
| 2 | 小王 | 20000 |详细 |
------------------
| 3 | 小李 | 80000 |详细 |
------------------
要求是点击详细后显示该当前员工的业务详细(orderview)如点击小王(图二)
------------------
| id | 姓名 | 业务总成绩 |
------------------
| 1 | 小张 | 100000 |详细 |
------------------
| 2 | 小王 | 20000 |详细 |
------------------
| 软件工程 |06-01-12 | 8000 |
------------------
| 网站开发 |06-11-10 | 12000 |
------------------
| 3 | 小李 | 80000 |详细 |
------------------
-------------------------------------------------------------
以下是我的做法:
我本以为这个用DataList嵌套一个GridView就OK的
但是问题来了。因为DataList里面的每一行都是一个table所以绑定后显示的table变得乱七八糟,比如:
本来要求绑定后的代码为
<table>
<tr>
<td>1</td>小张<td>100000</td><td>详细</td>
</tr>
....
</table>
但是用DataList绑定后为
<table>
<tr>
<td>
<table>
<tr>
<td>1</td>小张<td>100000</td><td>详细</td>
</tr>
</table>
</td>
</tr>
....
</table>
这种格式造成数据没有对齐
做如果用GridView绑定的话图一的功能没有问题
但图二的功能就不知道要怎么实现了请问这个问题要怎么解决
------------------
| id | 姓名 | 业务总成绩 | |
------------------
| 1 | 小张 | 100000 |详细 |
------------------
| 2 | 小王 | 20000 |详细 |
------------------
| 3 | 小李 | 80000 |详细 |
------------------
要求是点击详细后显示该当前员工的业务详细(orderview)如点击小王(图二)
------------------
| id | 姓名 | 业务总成绩 |
------------------
| 1 | 小张 | 100000 |详细 |
------------------
| 2 | 小王 | 20000 |详细 |
------------------
| 软件工程 |06-01-12 | 8000 |
------------------
| 网站开发 |06-11-10 | 12000 |
------------------
| 3 | 小李 | 80000 |详细 |
------------------
-------------------------------------------------------------
以下是我的做法:
我本以为这个用DataList嵌套一个GridView就OK的
但是问题来了。因为DataList里面的每一行都是一个table所以绑定后显示的table变得乱七八糟,比如:
本来要求绑定后的代码为
<table>
<tr>
<td>1</td>小张<td>100000</td><td>详细</td>
</tr>
....
</table>
但是用DataList绑定后为
<table>
<tr>
<td>
<table>
<tr>
<td>1</td>小张<td>100000</td><td>详细</td>
</tr>
</table>
</td>
</tr>
....
</table>
这种格式造成数据没有对齐
做如果用GridView绑定的话图一的功能没有问题
但图二的功能就不知道要怎么实现了请问这个问题要怎么解决
http://dotnet.aspx.cc/article/f73eeaa9-2bdc-47fd-afd2-59f2fa4897f5/read.aspx
----------------
<div style="width: 100%; padding: 2px; font-weight: bold; background-color: #DEDEDE;
float: left">
<span style="float: left">栏目名称:<%#Eval("Title") %></span><span style="float: right;
color: Red; cursor: pointer" onclick="ShowHidden('<%#Eval("id") %>',event)">隐藏</span></div>
<div style="background-color: #FFF; padding-left: 60px; clear: both" id="div<%#Eval("id") %>">
-------------------
这个是你年说的显示| id | 姓名 | 业务总成绩 | |
明显你的是用Div做的。如因为你那个只有两列一个左一个右所以多了也不会错乱
而我的是显示一条记录有所多的字段如果像你这样写的话
记录多的话一定会出现错乱的而不会像用GridView绑定的那样整齐
我也想过自己写Table但这样的话要行里面有事件的话写起来就非常麻烦
{
GridViewRow row = new GridViewRow(e.Row.RowIndex + 1, e.Row.RowIndex, DataControlRowType.DataRow, DataControlRowState.Normal);
this.GridView1.Controls[0].Controls.Add(row);
row.Cells.Add(new TableCell());
row.Cells[0].ColumnSpan = e.Row.Cells.Count;
row.Cells[0].Text = "<TABLE WIDTH ='100%' ><TR><TD>AA</TD><TD>BB</TD><TD>CC</TD></TR></TABLE>";
Response.Write(row.Cells.Count.ToString() + "**");
}
你的想法是不是
在点击详细的时候
给gridview添加一行
然后合并这一行
添加一个table?
如果是这样的话
row.Cells[0].Text
可不可以为
row.Cells[0].Controls.Add(GridView);
这样方便操作详细里面的数据?
<Columns>
<asp:BoundField DataField="Key" HeaderText="Key" />
<asp:BoundField DataField="Value" HeaderText="Value" />
<asp:ButtonField ButtonType="Button" Text="详细" CommandName="detail" />
</Columns>
</asp:GridView>
<asp:Repeater ID="rp1" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<td>类别</td>
<td>时间</td>
<td>金额</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<TR>
<td><%#Eval("A")%></td>
<td><%#Eval("B")%></td>
<td><%#Eval("C")%></td>
</TR>
</ItemTemplate>
<FooterTemplate>
</TABLE>
</FooterTemplate>
</asp:Repeater>
{
System.Collections.Hashtable ht = new Hashtable();
ht.Add("AA", true);
ht.Add("BB", false);
ht.Add("CC", "2");
ht.Add("DD", "3");
ht.Add("EE", "3");
this.GridView1.DataSource = ht;
this.GridView1.DataBind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "detail")
{
int iIndex = Convert.ToInt32(e.CommandArgument);
GridViewRow row = this.GridView1.Rows[iIndex];
GridViewRow NewRow = new GridViewRow(iIndex + 1, iIndex, DataControlRowType.DataRow, DataControlRowState.Normal);
NewRow.Cells.Add(new TableCell());
NewRow.Cells[0].ColumnSpan = row.Cells.Count;
DataTable dt = new DataTable();
dt.Columns.Add("A", typeof(string));
dt.Columns.Add("B", typeof(string));
dt.Columns.Add("C", typeof(Int32));
DataRow r1 = dt.NewRow();
r1[0] = "软件工程";
r1[1] = "06-01-12";
r1[2] = 8000;
dt.Rows.Add(r1);
r1 = dt.NewRow();
r1[0] = "网站开发";
r1[1] = "06-11-10";
r1[2] = 12000;
dt.Rows.Add(r1);
this.rp1.DataSource = dt.DefaultView;
this.rp1.DataBind();
this.GridView1.Controls[0].Controls.AddAt(iIndex+2,NewRow); NewRow.Cells[0].Controls.Add(this.rp1);
}