再描叙一下,就是在DataGrid中只包含
“绑定列”
“超级链接列”
“模板列”
时,程序会处理ImageButton的事件但是如果含有
“按钮列”则程序不执行!
“绑定列”
“超级链接列”
“模板列”
时,程序会处理ImageButton的事件但是如果含有
“按钮列”则程序不执行!
解决方案 »
- myxls使用问题
- 求一个最简单的三层架构的例子
- aspx文件放在根目录下,其上的中文(Label等)是正常显示,但是放在根目录的下级目录就显示乱码,为什么?怎么解决
- 关于生成静态页面的问题
- |M| 最近在做了网上找了一个曲线图,想大家看看这几句是什么意思
- 连接数据库出错!
- table中单元格td中的字体怎么调整大小??
- 再次高分求教:ASP。NET中使用IE本身的打印功能,怎样在程序中设定页面纸张的横向、纵向,以及纸型的大小、还有怎样去掉页眉、页脚?
- 这句话sb.Append("@v_bxr,@v_bxdw,@v_bxdd,@v_gznr)");报错“常数中有换行符”???怎么回事
- 为什么DataGrid.Columns.Count只有1???
- 怎么实现根据查询出来的图片动态的放到页面上,页面宽度固定而长度动态改变
- 下面这段ASP.NET代码为何编译出错???
还有你的按钮列的代码贴出来看看吧
<asp:datagrid id="DG1" runat="server" Width="528px" AutoGenerateColumns="False">
<EditItemStyle Wrap="False" HorizontalAlign="Center"></EditItemStyle>
<ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
<HeaderStyle Wrap="False" HorizontalAlign="Center"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="ID" ReadOnly="True" HeaderText="编号">
<HeaderStyle Wrap="False" HorizontalAlign="Center"></HeaderStyle>
<ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="GroupName" ReadOnly="True" HeaderText="组名称">
<HeaderStyle Wrap="False" HorizontalAlign="Center"></HeaderStyle>
<ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" CancelText="取消" EditText="查看/编辑">
<ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
</asp:EditCommandColumn>
<asp:TemplateColumn>
<ItemStyle Width="50px"></ItemStyle>
<ItemTemplate>
<asp:LinkButton CommandName="Image" Runat="server" CausesValidation="False">sadfsdf</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemStyle Width="50px"></ItemStyle>
<ItemTemplate>
<asp:ImageButton CommandName="ImageBtn" Runat="server" ImageUrl="../../images/delete.gif" CausesValidation="False"
ID="Linkbutton1"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid><asp:label id="Label1" runat="server" Width="520px"></asp:label>
//绑定代码
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
DG1.DataBind();
}private void InitializeComponent()
{
this.ButAdd.Click += new System.EventHandler(this.ButAdd_Click);
this.DG1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DG1_ItemCommand);
this.DG1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DG1_EditCommand);
this.DG1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DG1_DeleteCommand);
this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
this.Load += new System.EventHandler(this.Page_Load); } public void DG1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string strID = e.Item.Cells[0].Text;
Response.Write("<script language=\"javascript\">parent.frames['leftFrame'].location.href='"+@"../../web/user_menu.aspx?type="+ConstValue.IntDRG.ToString()+"&id="+strID+"';</script>");
Response.Write("<script language=\"javascript\">this.location.href='EditDRG.aspx?id="+strID+"&type="+ConstValue.IntEDIT.ToString()+"';</script>");
} public void DG1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Label1.Text = "";
string strID = e.Item.Cells[0].Text;
DTDRG = objDRG.GetAll();
int intRes = DelTree(strID);
if(intRes!=-1)
{
DTDRG = objDRG.GetAll();
DG1.DataSource = DTDRG;
DG1.DataBind();
}
else
{
Label1.Text = "删除失败";
}
}public void DG1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
ImageButton ib = (ImageButton)e.CommandSource;
this.Label1.Text = ib.CommandName; switch (e.CommandName)
{
case "Image":
this.Label1.Text = "click";
break;
case "ImageBtn":
this.Label1.Text = "imageButton";
break;
} }
{
//可以加一行(我没加大小写):
response.write("名字:"+e.CommandName);
response.end()
ImageButton ib = (ImageButton)e.CommandSource;
this.Label1.Text = ib.CommandName; switch (e.CommandName)
{
case "Image":
this.Label1.Text = "click";
break;
case "ImageBtn":
this.Label1.Text = "imageButton";
break;
}
imagebutton的autopostback=true
创建用于控件的 ItemCommand 事件的方法。在该方法中,执行下列操作:
检查事件参数对象的 CommandSource 属性的 CommandName 属性,查看传递的是什么字符串。
为用户单击的按钮执行相应的逻辑。
注意 如果您调用了父控件(DataList、Repeater 或 DataGrid 控件)的 DataBind 方法,ItemCommand 事件将不会发生,原因是父控件的内容已经重置。因此,您通常不需要在每次往返时调用 DataBind 方法(即在初始化页时无需检查发回)。有关详细信息,请参见数据绑定多记录 Web 服务器控件和在设计时数据绑定单值 Web 服务器控件。
一定要写
if( !IsPostBack)
{
GridBind()
}