新手求教,子窗口获得父窗口数据问题

秋杨 2012-08-17 03:33:55
因工作原因,小弟第一次学做网页,效果是查询到数据后进行修改的功能
用showModalDialog弹出修改子窗口,界面是一竖排的TextBox对应父窗口GridView的一行
想要弹出是对其需要的修改每个TextBox默认显示出GridView的数据
对于web还处于新手学习阶段,很多基础的知识都不清楚,只能摸索着学习了,
该如何实现呢
附上GridView的创建代码,是不是可以按照newrow.Cell[i]和tcRow[j]进行对应啊?

protected void GridView1_RowCreated( object sender , GridViewRowEventArgs e )
{
TableCellCollection tcRow = e.Row.Cells;

switch(e.Row.RowType)
{
case DataControlRowType.Header:

GridViewRow newrow=new GridViewRow(0,0, DataControlRowType.Header,DataControlRowState.Normal);
newrow.Visible=true;

for(int i=0;i<tcRow.Count;i++)
{
TableCell tc=new TableCell();
tc.Text=tcRow[i].Text;
tc.VerticalAlign=VerticalAlign.Middle;
tc.HorizontalAlign=HorizontalAlign.Center;
newrow.Cells.Add(tc);
}

newrow.Cells[0].RowSpan=2;
newrow.Cells[1].RowSpan=2;
newrow.Cells[2].RowSpan=2;
newrow.Cells[3].RowSpan=2;
newrow.Cells[4].RowSpan=2;
newrow.Cells[5].ColumnSpan=2;
newrow.Cells.RemoveAt(6);
newrow.Cells[6].RowSpan=2;
newrow.Cells[7].ColumnSpan=2;
newrow.Cells.RemoveAt(8);
newrow.Cells[8].ColumnSpan=2;
newrow.Cells.RemoveAt(9);
newrow.Cells[9].ColumnSpan=2;
newrow.Cells.RemoveAt(10);
newrow.Cells[10].ColumnSpan=2;
newrow.Cells.RemoveAt(11);
newrow.Cells[11].RowSpan=2;
newrow.Cells[12].RowSpan=2;

tcRow[0].Text="Min";
tcRow[1].Text="Max";
tcRow[2].Text="Min";
tcRow[3].Text="Max";
tcRow[4].Text="Min";
tcRow[5].Text="Max";
tcRow[6].Text="Min";
tcRow[7].Text="Max";
tcRow[8].Text="Min";
tcRow[9].Text="Max";

for ( ; tcRow.Count > 10; )
{
tcRow.RemoveAt( 10 );
}

GridView1.Controls[0].Controls.AddAt(0,newrow);
break;

case DataControlRowType.DataRow:
break;
}
}
...全文
107 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
秋杨 2012-08-17
  • 打赏
  • 举报
回复
谢谢,还请问
能不能直接获取GridView各列的数据呢?如果可以,能给出详细的获取数据的代码么?
就像代码里,可不可以用newrow.Cell[i]或者tcRow[j]这样子来获取呢?
如果不行,那就只能先把ID传参给子窗口,然后调用数据库获取各项的值?
shizhu820228 2012-08-17
  • 打赏
  • 举报
回复
写在Page_Load里啊。
秋杨 2012-08-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
可以把GRIDVIEW中的ID传过去,执行查询赋值。
也可以把选中的条的对象传过去,进行赋值。
[/Quote]
谢谢
第一种是不是需要用到SQL语句?因为需要列出的是每一列的数据。
还有,如何在弹出子窗口的时候就显示在TextBox里呢?应该怎么写,写哪里?
shizhu820228 2012-08-17
  • 打赏
  • 举报
回复
可以把GRIDVIEW中的ID传过去,执行查询赋值。
也可以把选中的条的对象传过去,进行赋值。

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧