int iIndex = Convert.ToInt32(e.CommandArgument);
这里面的e.commandargument取得的是什么值在前台中的 <asp:ButtonField ButtonType="Button" Text="详细" CommandName="detail" />并没有commandargument值啊
我点击这里他的值是当前的行index那这个是不是这个意思 GridViewRow row = this.GridView1.Rows[iIndex];
GridViewRow NewRow = new GridViewRow(iIndex + 1, iIndex, DataControlRowType.DataRow, DataControlRowState.Normal);
//这一行的中(iIndex + 1, iIndex, DataControlRowType.DataRow, DataControlRowState.Normal);
其中DataControlRowType.DataRow, DataControlRowState.Normal指的是新行为什么类型和状态,不明白的是前面的iIndex + 1, iIndex, NewRow.Cells.Add(new TableCell());
//为什么这里还要NewRow.Cells.Add(new TableCell());有什么作用
NewRow.Cells[0].ColumnSpan = row.Cells.Count;... ... this.GridView1.Controls[0].Controls.AddAt(iIndex + 2, NewRow); NewRow.Cells[0].Controls.Add(this.rp1);
这里面的e.commandargument取得的是什么值在前台中的 <asp:ButtonField ButtonType="Button" Text="详细" CommandName="detail" />并没有commandargument值啊
我点击这里他的值是当前的行index那这个是不是这个意思 GridViewRow row = this.GridView1.Rows[iIndex];
GridViewRow NewRow = new GridViewRow(iIndex + 1, iIndex, DataControlRowType.DataRow, DataControlRowState.Normal);
//这一行的中(iIndex + 1, iIndex, DataControlRowType.DataRow, DataControlRowState.Normal);
其中DataControlRowType.DataRow, DataControlRowState.Normal指的是新行为什么类型和状态,不明白的是前面的iIndex + 1, iIndex, NewRow.Cells.Add(new TableCell());
//为什么这里还要NewRow.Cells.Add(new TableCell());有什么作用
NewRow.Cells[0].ColumnSpan = row.Cells.Count;... ... this.GridView1.Controls[0].Controls.AddAt(iIndex + 2, NewRow); NewRow.Cells[0].Controls.Add(this.rp1);
NewRow.Cells.Add(new TableCell());是不是添加列
(是不是添加行的时候行是什么也没有的,要添加列才会有内容显示)
这个行还没有单元格.
必须手工添加
所以不知道这两个是什么意思
我把他们换成别的也不会出错比如:0,0,
这个行还没有单元格.
必须手工添加
-----------------------
这里一添加他的单无格的数量就会为上一行的单无格数吗?
应该只有一个啊
而且他还没有
this.GridView1.Controls[0].Controls.AddAt(iIndex + 2, NewRow);
怎么可以
NewRow.Cells[0].ColumnSpan = row.Cells.Count;
这个时候NewRow.cells数应为1才对啊
===========
因为这个row是手工添加的,所以这个rowIndex和DataItemIndex没有了意义.
但是new 的时候必须指定这个参数.
NewRow.Cells[0].ColumnSpan = row.Cells.Count;
这个时候NewRow.cells数应为1才对啊
=========
没错,但 = 号后面是 row row是原来的row,现存的
GridViewRow row = this.GridView1.Rows[iIndex];
<Columns>
<asp:BoundField DataField="Key" HeaderText="Key" />
<asp:BoundField DataField="Value" HeaderText="Value" />
<asp:TemplateField>
<ItemTemplate>
<input type="button" value="显示" onclick="GoShowDetail(this,1);" />
<input type="button" value="隐藏" onclick="GoShowDetail(this,2);" />
</ItemTemplate>
</asp:TemplateField>
</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>
<script type="text/javascript">
function GoShowDetail(btn,i)
{
var tr = btn.parentElement.parentElement.nextSibling;
tr.style.display = (i==1)?"":"none";
}
</script>
去掉原来的rowcommand事件.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
GridViewRow NewRow = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
NewRow.Cells.Add(new TableCell());
NewRow.Cells[0].ColumnSpan = row.Cells.Count;
//NewRow.Cells[0].Controls.Add(this.rp1);
NewRow.Style.Add("display","none"); 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.Add(NewRow);
//this.rp1.RenderControl(Html32TextWriter);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
Html32TextWriter tr = new Html32TextWriter(new System.IO.StringWriter(sb));
this.rp1.RenderControl(tr);
NewRow.Cells[0].Text = sb.ToString();
}
<script type="text/javascript">
function GoShowDetail(btn,i)
{
var tr = btn.parentElement.parentElement.nextSibling;
tr.style.display = (i==1)?"":"none";
}
</script>
可不可以在用户点击显示的时候再加载相应的记录的方法
===========
可是可以的,但比较麻烦.要在ItemCreated事件中写,先在command中做记号,然后在command中写,
这样才能保存生成的html.
慕白老兄==牛人==true
=======
在ViewState中放个值吧.个人认为一次全部显示在客户端比较好,
这样避免反复提交,
因为gridview如果带分页的rows条数有限,所以生成html代价不是很大.
然后在RowDataBound判断当前绑定ID是否有相同的
有就显示然后在rowcommand中点击显示的时候添加这个ID
点击隐藏的时候删除这个ID请问是不是这样
-----------------------冒昧问下,学习几年了哦?