各位:
请教一个GridView RowCommond事件的问题
背景:我在GridView中增加了一个模板列,里面增加了一个按钮
问题:
1.如果我增加的控件为Button,则无法触发RowCommond事件,为什么?
2.如果增加的控件为LinkButton,则可以触发RowCommond事件,但是无法执行RowCommond事件中的Page.ClientScript.RegisterStartupScript,JS无效代码如下(GridView中已经增加了RowCommon的事件调用):
aspx端代码:
onrowcommand="GridReportList_RowCommand"<asp:TemplateField HeaderText="操作" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="btnRowConfirm" runat="server" Text="结果确认" CommandName="ConfirmResult"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>CS端代码:
protected void GridReportList_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ConfirmResult")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "alert('ddddd');", true);
}
}
请教一个GridView RowCommond事件的问题
背景:我在GridView中增加了一个模板列,里面增加了一个按钮
问题:
1.如果我增加的控件为Button,则无法触发RowCommond事件,为什么?
2.如果增加的控件为LinkButton,则可以触发RowCommond事件,但是无法执行RowCommond事件中的Page.ClientScript.RegisterStartupScript,JS无效代码如下(GridView中已经增加了RowCommon的事件调用):
aspx端代码:
onrowcommand="GridReportList_RowCommand"<asp:TemplateField HeaderText="操作" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="btnRowConfirm" runat="server" Text="结果确认" CommandName="ConfirmResult"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>CS端代码:
protected void GridReportList_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ConfirmResult")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "alert('ddddd');", true);
}
}
解决方案 »
- 未知COM异常
- 在ASP.NET中如何读取excel的文件,计算以后在生成一个新的excel文件啊
- 如何给WebConfig中数据库连接密码加密?
- 求求大家了,帮帮我这个可怜的孩子吧
- 解答立刻给分!***小女子刚刚已经给大家结了200分了,c#开发的activex还有一点问题请教
- 如何把一个string 型的字符串存到SQL中的Binary字段中?在线等,谢谢!
- Visual C#2005 Express Edition 做不了web开发?愣没找到创建web的工程文件。达人求教!
- 关于throw 异常的问题(Duwamish7)
- 如果一个用户登陆了,怎么判断使在另一个客户机不能用同一个用户名登陆?
- 在ASP.NET中如何实现如C#中的TabControl的效果呢??
- 有玩淘宝网API的请进
- IIS6
{
if (e.CommandSource.GetType() == typeof(LinkButton) && e.CommandName == "ConfirmResult")
{
this.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('ddddd');</script>");
}
}
这句话,我单步调试是可以运行的,只是没有出现结果。
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="120000">
</asp:Timer>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" CombineScripts="false">
</asp:ToolkitScriptManager>
<asp:GridView ID="GridReportList" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="3"
DataKeyNames="EQPID,BUYOFFRESULT,BUYOFFSTARTTIME,BUYOFFENDTIME,LOTID,ALUMINIUMTHICKNESS,FLAG,WIRE"
OnRowCreated="GridReportList_RowCreated"
Width="100%" onrowdatabound="GridReportList_RowDataBound"
AllowSorting="True" onsorting="GridReportList_Sorting"
onrowcommand="GridReportList_RowCommand">
<FooterStyle BackColor="White" ForeColor="Black" />
<RowStyle BackColor="#F8F8F8" />
<PagerStyle BackColor="#F8F8F8" ForeColor="Red" HorizontalAlign="Left" />
<SelectedRowStyle CssClass="mover" />
<HeaderStyle CssClass="toptrbg" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="EQPID" HeaderText="设备号" SortExpression="EQPID">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="LOTID" HeaderText="批号" SortExpression="LOTID">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="BUYOFFRESULT" HeaderText="Buy Off结果" SortExpression="BUYOFFRESULT">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="BUYOFFSTARTTIME" HeaderText="Buy Off开始时间" SortExpression="BUYOFFSTARTTIME">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="BUYOFFENDTIME" HeaderText="Buy Off结束" SortExpression="BUYOFFENDTIME">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="操作" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="btnRowConfirm" runat="server" Text="结果确认" CommandName="ConfirmResult"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
例如下面这句就可以执行
protected void btnresultaffirm_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "showdiv('');", true);
}
这样看行不行。
厉害!没错,OK了,THKS
这个帖子还有一个问题:如果我增加的控件为Button,则无法触发RowCommond事件,为什么?
<asp:TemplateField HeaderText="操作" ShowHeader="False">
<ItemTemplate>
<asp:Button ID="btnRowConfirm" runat="server" Text="结果确认" CommandName="ConfirmResult"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
前台:<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/post_button_delete.gif" OnClientClick="javascript:return confirm('确实要删除吗?')" CommandName="MyDelete" CommandArgument='<%#Eval("ID") %>' />
</ItemTemplate>
</asp:TemplateField>后台在RowCommand事件中这样写:protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "MyDelete")
{
string ID = e.CommandArgument.ToString();
sqlString = "delete from tb_Standard where ID='" + ID + "'";
if (dp.updateData(sqlString) > 0)
{
Response.Write("<script> alert('删除成功!');window.location.href='StandardM.aspx' </script>");
}
else
{
Response.Write("<script> alert('删除失败!') </script>");
}
GridView1.DataBind();
}
}基本上就没什么问题了,你可以试一下