repeater或datagird在Form_Load事件中
1. 如果你使用了if(!postback){databind();}
那么动态创建的控件将不能触发ItemCommand事件2. 如果你的绑定语句没有加postback的判断
那么就更严重了,itemcommand会执行,但是执行的是第二次绑定的commandargument,就产生逻辑BUG了我的repeater里面的没一行数据都对应着创建了对应个数不一的按钮,状态可能在其他用户操作下发生改变,
所以不能由第二次在postback时绑定的数据做itemcommand大家有什么解决办法没?
1. 如果你使用了if(!postback){databind();}
那么动态创建的控件将不能触发ItemCommand事件2. 如果你的绑定语句没有加postback的判断
那么就更严重了,itemcommand会执行,但是执行的是第二次绑定的commandargument,就产生逻辑BUG了我的repeater里面的没一行数据都对应着创建了对应个数不一的按钮,状态可能在其他用户操作下发生改变,
所以不能由第二次在postback时绑定的数据做itemcommand大家有什么解决办法没?
解决方案 »
- Asp.net 获取指定目录下的后缀名为“.doc” 的所有文件名和文件路径,帮写一个方法
- 如何取得RadioButtonList 各项的id
- 1和0.9的无限循环哪个大?记得给个理由
- 水晶报表里怎么画的表格怎样才能闭合?
- 求一正则表达式
- 出50分问一个小问题!!!
- 关于以前的菜鸟写的 asp.net页面,经常被攻击!
- 在写一个登陆的东西,密码学的!请高手帮忙!
- 大哥,大姐,,,,救命呀,,,我的程序是asp和.net程序在一起的,现在老是用户无故Session过期,被踢出来?
- asp.net 一个页面关闭同时刷新另一个页面的值
- 【发帖带散300分】重量级地查询控件
- ReportViewer点击打印按钮后会触发什么事件?
<tr>
<td><%#Eval("id") %></td>
<td><asp:Button ID="Button1" runat="server" Text="Button" OnCommand="btnGrid_Command" CommandArgument='<%#Eval("name") %>' /></td>
</tr>
</ItemTemplate>
<div runat="server" id="Panel1"></div>
protected void Page_Load(object sender, EventArgs e)
{ Button btn = new Button();
btn.Text = "按钮";
btn.CommandArgument = "CommandArgument";
btn.Command += new CommandEventHandler(btnGrid_Command);
this.Panel1.Controls.Add(btn); }
protected void btnGrid_Command(object sender, CommandEventArgs e)
{
}
//protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
//{
// if (e.CommandName == "MyCommand")
// {
// Button button = (Button)e.CommandSource;
// GridViewRow row = (GridViewRow)button.Parent.Parent;
// string a = row.Cells[1].Text.ToString();//获得第一个单元格的值
// string b = this.GridView1.DataKeys[row.DataItemIndex].Values[0];//获得DataKeys的值
// }
//}
看看问题,现在根本不能触发Command,如果不加回发判断,数据已经改变了。
{
if(!IsPostBack)
{
、、、、、
}
}
这里面的问题 我的已经解决了