如何在帖子中找到网页上的网格控件? [英] How do I find a grid control ona web page in a post back?

查看:50
本文介绍了如何在帖子中找到网页上的网格控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个.NET网页,我们动态创建一堆DataGrids和

将它们添加到占位符。当用户点击提交时,我们需要通过

所有DataGrids来获取一些数据。我们似乎无法在帖子后面找到

的网格,PlaceHolder.Controls.Count为0.我们如何获得这些数据

返回。 />

DataGrids具有用户可能已检查过的复选框。那些是我们想要获得的行,所以我们不能只是重新查询和重新绑定。


任何想法?


谢谢,

Jim

We ahve a .NET web page that we dynamically create a bunch of DataGrids and
add them to a place holder. When the user hits submit we need to go through
all of the DataGrids to get some data. We can''t seem to find the grids on
the post back, the PlaceHolder.Controls.Count is 0. How do we get that data
back.

The DataGrids have check boxes that the user may have checked. Those are
the rows we want to get so we can''t just requery and rebind.

Any ideas?

Thanks,
Jim

推荐答案



吉姆,

感谢您在此论坛中发帖。

根据我的理解,您想动态创建一些数据网格并将

添加到占位符,但是当你回发时,你会发现占位符'

子控件集合是空的。

我没有看到你的代码,但我认为当回发时你可能会忘记

重新创建数据网格并重新绑定到这些控件。

如果你喜欢这样,它应该有效。下面列出的代码片段:


private void Page_Load(object sender,System.EventArgs e)

{

//置放用户在这里初始化页面的代码

dg1 = new DataGrid();

DataGrid dg2 = new DataGrid();

DataGrid dg3 = new DataGrid ();

SqlDataAdapter adapter = new SqlDataAdapter(" select * from

jobs"," server = localhost; database = pubs; uid = sa; pwd =" ;);

DataSet ds = new DataSet();

adapter.Fill(ds);

dg1.DataSource = ds;

dg1.DataBind();

dg2.DataSource = ds;

dg2.DataBind();

dg3。 DataSource = ds;

dg3.DataBind();

PlaceHolder1.Controls.Add(dg1);

PlaceHolder1.Controls.Add(dg2 );

PlaceHolder1.Controls.Add(dg3);

}


私有void Button1_Click(对象发送者,System.EventArgs) e)

{

Response.Write(PlaceHolder1.Controls.Count.ToStrin g());

}


祝你好运,

Jeffrey Tan

微软在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有赋予权利。


Hi Jim,

Thanks for posting in this group.
Based on my understanding, you wanted to dynamic create some datagrids and
add to the placeholder, but when you postback, you find the placeholder''s
child control collection is empty.
I did not see you code, but I think when postback you may forget to
recreate the datagrids and rebind to these controls.
If you do like this, it should work. Code snippet listed below:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
dg1=new DataGrid();
DataGrid dg2=new DataGrid();
DataGrid dg3=new DataGrid();
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=" );
DataSet ds=new DataSet();
adapter.Fill(ds);
dg1.DataSource=ds;
dg1.DataBind();
dg2.DataSource=ds;
dg2.DataBind();
dg3.DataSource=ds;
dg3.DataBind();
PlaceHolder1.Controls.Add(dg1);
PlaceHolder1.Controls.Add(dg2);
PlaceHolder1.Controls.Add(dg3);
}

Private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write(PlaceHolder1.Controls.Count.ToStrin g());
}

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


我明白了,但问题是我无法从数据库中获取数据

再次出于两个原因。 1它可能已经改变了,2我试图从用户选择的数据网格中获取

项目。如果我重新加载它们我不知道

他们选择了哪些项目。特别是如果一个新的记录在旧的那个中间的
中间形成。


这些数据网格有一个复选框列。我需要通过网格和

找到哪些行被检查。

谢谢,

jim


"" Jeffrey Tan [MSFT]"" <,V - ***** @ online.microsoft.com>在消息中写道

news:15 ************** @ cpmsftngxa07.phx.gbl ...
I understand that, but the problem is I can''t get the data from the database
again for 2 reasons. 1 It may have changed, and 2 I''m trying to get the
items the user selected form the datagrids. If I reload them I don''t know
which items they selected. Especially if a new record comed back in the
middle of the old ones.

These datagrids have a checkbox column. I need to go through the grids and
find which rows were checked.
Thanks,
jim

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:15**************@cpmsftngxa07.phx.gbl...

你好Jim,

感谢您在此论坛中发帖。
根据我的理解,您想动态创建一些数据网格并添加到占位符,但是当您回发时,您会发现占位符'
子控件集合是空的。
我没有看到你的代码,但我认为当回发时你可能忘记重新创建数据网格并重新绑定到这些控件。 />如果你喜欢这个,它应该工作。下面列出的代码片段:

private void Page_Load(object sender,System.EventArgs e)
//
//将用户代码置于此处初始化页面
dg1 = new DataGrid();
DataGrid dg2 = new DataGrid();
DataGrid dg3 = new DataGrid();
SqlDataAdapter adapter = new SqlDataAdapter(" select * from
jobs" ,server = localhost; database = pubs; uid = sa; pwd =");
DataSet ds = new DataSet();
adapter.Fill(ds);
dg1。 DataSource = ds;
dg1.DataBind();
dg2.DataSource = ds;
dg2.DataBind();
dg3.DataSource = ds;
dg3。 DataBind();
PlaceHolder1.Controls.Add(dg1);
PlaceHolder1.Controls.Add(dg2);
PlaceHolder1.Controls.Add(dg3);
}

私有void Button1_Click(对象发送者,System.EventArgs e)
{
Response.Write(PlaceHolder1.Controls.Count.ToStrin g());
}

致以最诚挚的问候,
Jeffrey Tan
微软在线合作伙伴支持
获得安全保障! - www.microsoft.com/security
此帖子提供就像没有保证,也没有授予任何权利。

Hi Jim,

Thanks for posting in this group.
Based on my understanding, you wanted to dynamic create some datagrids and
add to the placeholder, but when you postback, you find the placeholder''s
child control collection is empty.
I did not see you code, but I think when postback you may forget to
recreate the datagrids and rebind to these controls.
If you do like this, it should work. Code snippet listed below:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
dg1=new DataGrid();
DataGrid dg2=new DataGrid();
DataGrid dg3=new DataGrid();
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=" );
DataSet ds=new DataSet();
adapter.Fill(ds);
dg1.DataSource=ds;
dg1.DataBind();
dg2.DataSource=ds;
dg2.DataBind();
dg3.DataSource=ds;
dg3.DataBind();
PlaceHolder1.Controls.Add(dg1);
PlaceHolder1.Controls.Add(dg2);
PlaceHolder1.Controls.Add(dg3);
}

Private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write(PlaceHolder1.Controls.Count.ToStrin g());
}

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.





嗨Jim,


感谢您的反馈。

出于第一个原因,我认为您应该将数据集存储在会话中

变量或viewstate,当回发时,您可以将数据网格绑定到

旧数据集。

出于第二个原因,如何实现行选择?在

webform datagrid?如果你通过复选框列实现它(我想这个

列也是你自己定制的),我想你可以在

中公开一个属性你的自定义复选框列返回它复选框的已检查状态。

下面的文章自定义复选框列,显示选中的复选框

州:
http://www.codeproject.com/aspnet/da...heckboxcol.asp


使用这2种方式,我认为你可以得到你想要的东西,如果还有

任何不清楚的地方,请随时告诉我。

祝你好运,

Jeffrey Tan

微软在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有赋予任何权利。


Hi Jim,

Thanks for your feedback.
For your first reason, I think you should store your dataset in session
variable or viewstate, when postback, you can bind your datagrid with the
old dataset.
For your second reason, how do you implement your "row selection" in
webform datagrid? If you implement it through checkbox column(I think this
column is also customized by you), I think you can expose a property in
your customized checkbox column which returns its checkbox''s checked state.
The article below customize a checkbox column expose the checkbox checked
state:
http://www.codeproject.com/aspnet/da...heckboxcol.asp

Use these 2 ways, I think you can get what you want, if there is still
anything unclear, please feel free to tell me.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


这篇关于如何在帖子中找到网页上的网格控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆