我页面中有一个DataGrid dg1
现在要求是在页面中动态添加两个DataGrid
样式和各种内容和这个dg1完全相同谢谢
现在要求是在页面中动态添加两个DataGrid
样式和各种内容和这个dg1完全相同谢谢
解决方案 »
- 应用程序试图执行安全策略不允许的操作。要授予此应用程序所需的权限,请与系统管理员联系,或在配置文件中更改该应用程序的信任级别。
- 如何打开一个没有最大化最新小化和关闭按钮的窗口
- 连接到当前页面,js不响应 onLoad 事件了?
- 没有安装IIS和VisualStudio的机器上如何运行ASP.net页面(.net framework安装了)?
- 帮忙推荐一本ASP.NET的书,谢谢!
- 交流界面的实现方法
- 奇怪现象……求救,高分……
- gridview关于编号自动增长问题
- 摄像头拍照相问题
- 多个文件同时上传,如何实现?
- java中的clone()方法对应的.net中是什么方法?
- 实际项目中数据库连接字符串
我有DataGrid,然后在他绑定的时候让他加多一行来绑定其他的表如下是幕白兄的代码:
DataGridItem item = e.Item;
//GridViewRow NewRow = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
DataGridItem NewItem = new DataGridItem(0, 0, ListItemType.Item);
NewItem.Cells.Add(new TableCell());
NewItem.Cells[0].ColumnSpan = item.Cells.Count;
NewItem.Style.Add("display", "none"); dgMovie.Controls[0].Controls.Add(NewItem);
DataGrid dg = new DataGrid();
dg.DataSource = MovieOrder.GetList();
dg.DataBind();
NewItem.Cells[0].Controls.Add(dg);
现在可以实现我给DataGrid的行绑定多一个DataGrid的问题
但是因为是new DataGrid我设计他里面的样式和绑定内容如果都用代码来写的话很是麻烦然后我就在外面自己设计了一个DataGrid然后代码为:
DataGridItem item = e.Item;
//GridViewRow NewRow = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
DataGridItem NewItem = new DataGridItem(0, 0, ListItemType.Item);
NewItem.Cells.Add(new TableCell());
NewItem.Cells[0].ColumnSpan = item.Cells.Count;
NewItem.Style.Add("display", "none"); dgMovie.Controls[0].Controls.Add(NewItem);
DataGrid dg = mydg; //这里是我自己设计的代码
dg.DataSource = MovieOrder.GetList();
dg.DataBind();
NewItem.Cells[0].Controls.Add(dg);
本来以为这样是可行的,但是程序运行的时候有生成多一个行,但却没有生成我要的那个DataGrid谢谢,上面要怎么改
DataGrid dg = dg_Item;
dg.DataSource = MovieOrder.GetList();
dg.DataBind();
NewItem.Cells[0].Controls.Add(dg);
还是不行.我给他加列
绑定也成功了
但是
<tr class="BTableText" style="display:none;">
<td align="center" colspan="6"></td>
</tr>
这是添加的行
但是
NewItem.Cells[0].Controls.Add(dg);
没有把他添加进来
但是我用new datagird()就可以
因为用new datagrid()
得出来的datagrid没有办法按我自己设计的样子
要是写代码又太多
所以想事先定一个
然后就直接在
DataGrid dg = dg_Item;
dg.DataSource = MovieOrder.GetList();
dg.DataBind();
NewItem.Cells[0].Controls.Add(dg);
这样而不用DataGrid dg = new datagrid()
<SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle CssClass="BTableText"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="Black" CssClass="BTableHead" BackColor="LightBlue" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="AgentPrice" HeaderText="代理价">
<HeaderStyle HorizontalAlign="Center" Font-Bold="True"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:BoundColumn>
<asp:BoundColumn DataField="SuggestPrice" HeaderText="建议价">
<HeaderStyle HorizontalAlign="Center" Font-Bold="True"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:BoundColumn>
<asp:BoundColumn DataField="WeekAgentPrice" HeaderText="周末代理价">
<HeaderStyle HorizontalAlign="Center" Font-Bold="True"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:BoundColumn>
<asp:BoundColumn DataField="WeekSuggestPrice" HeaderText="周末建议价">
<HeaderStyle HorizontalAlign="Center" Font-Bold="True"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:BoundColumn>
<asp:BoundColumn DataField="MovieTypeID" HeaderText="票类型">
<HeaderStyle HorizontalAlign="Center" Font-Bold="True"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
后台绑定
protected void dgMovie_ItemDataBound(object sender, DataGridItemEventArgs e)
{
DataGridItem item = e.Item;
//GridViewRow NewRow = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
DataGridItem NewItem = new DataGridItem(0, 0, ListItemType.Item);
NewItem.Cells.Add(new TableCell());
NewItem.Cells[0].ColumnSpan = item.Cells.Count;
NewItem.Style.Add("display", "none"); dgMovie.Controls[0].Controls.Add(NewItem);
DataGrid dg =dg_Item;
//DataGrid dg = new DataGrid();
dg.DataSource = MovieOrder.GetList();
dg.DataBind();
NewItem.Cells[0].Controls.Add(dg);
}
??这行应该去掉
<tr class="BTableText">
<td align="center" colspan="6"></td>
</tr>