GridView的RowCommand事件和DataList的ItemCommand事件
来源:互联网 发布:工作计划软件app 编辑:程序博客网 时间:2024/05/22 16:51
GridView:
<asp:GridView ID="GridView1" runat="server" CssClass="GridViewStyle" PageSize="10" AllowPaging="true" onpageindexchanging="GridView1_PageIndexChanging" onrowcommand="GridView1_RowCommand"> <FooterStyle CssClass="GridViewFooterStyle" /> <RowStyle CssClass="GridViewRowStyle" /> <SelectedRowStyle CssClass="GridViewSelectedRowStyle" /> <PagerStyle CssClass="GridViewPagerStyle" /> <AlternatingRowStyle CssClass="GridViewAlternatingRowStyle" /> <HeaderStyle CssClass="GridViewHeaderStyle"/> <Columns> <asp:BoundField DataField="DRName" HeaderText="饭店名称" /> <asp:BoundField DataField="Category" HeaderText="所属菜系" /> <asp:BoundField DataField="ConsumptionLevel" HeaderText="人均消费" /> <asp:BoundField DataField="Remark" HeaderText="折扣" ControlStyle-Width="80px" /> <asp:BoundField DataField="Telephone" HeaderText="联系电话" /> <asp:TemplateField> <ItemTemplate> <asp:Button ID="btnDetails" runat="server" Text="详细" CommandName="GetID" CommandArgument='<%#eval_r("ID") %>'/> </ItemTemplate> </asp:TemplateField> </Columns> <EmptyDataTemplate> 提示:当前没有任何记录 </EmptyDataTemplate> </asp:GridView> protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { try { int id = Convert.ToInt32(e.CommandArgument); switch (e.CommandName) { case "GetID": Server.Transfer("iframeRepeater.aspx?ID=" + id.ToString()); break; } } catch { } }
DataList
<asp:DataList ID="DataList1" runat="server" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="0" CellPadding="3" GridLines="Both" RepeatColumns="3" RepeatDirection="Horizontal" Width="99%" HorizontalAlign="Center" ItemStyle-BorderWidth="1" onitemcommand="DataList1_ItemCommand" > <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#669999"></SelectedItemStyle> <ItemStyle ForeColor="#000066" VerticalAlign="Top" Width="33%"></ItemStyle> <ItemTemplate> <table cellpadding="1" cellspacing="0" height="220" border="0" width="80%"> <tr> <td align="center" style="height: 95px"> <a href='Repeater.aspx?num=<%#eval_r("shopNum") %>'> <img src='<%#eval_r("ShopImage") %>' height="250px" width="250px" /></a> </td> </tr> <tr> <td align="center"> <a href='Repeater.aspx?num=<%#eval_r("shopNum")%>'> <%#eval_r("shopName")%></a> </td> </tr> <tr> <td align="center"> <%#eval_r("shopPhone")%> <asp:Button ID="btnDetails" runat="server" Text="详细" CommandName="showDetails" CommandArgument='<%#Eval ("shopNum") %>'/> </td> </tr> </table> </ItemTemplate> </asp:DataList> protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) { try { string num = e.CommandArgument.ToString(); switch (e.CommandName) { case "showDetails": Server.Transfer("Repeater.aspx?num=" + num); break; } } catch { } }eg:
(1)aspx:
<asp:DataList ID="dlServiceItem" runat="server" Width="100%"> <ItemTemplate> <div class="Items_ContentLine" style="text-align:left;"> <div class="Items_ContentLineLeft"> <a href='WxServiceItem_View.aspx?Id=<%# Eval("ItemId")%>' title="查看明细" target="_blank" class="ItemsA"><%# Eval("ItemName")%></a> </div> <div class="Items_ContentLineRight"> <asp:HyperLink ID="hlFlow" runat="server" Text="123" NavigateUrl="#" CssClass="serviceItem_Button" Width="63px" Height="38px"></asp:HyperLink> <asp:HyperLink ID="hlAttach" runat="server" Text="123" NavigateUrl="#" CssClass="serviceItem_Button" Width="63px" Height="38px"></asp:HyperLink> <asp:Button ID="btnProcess" runat="server" Text="123" CssClass="serviceItem_Button" Width="63px" Height="38px" BorderWidth="0" BackColor="Transparent" CommandName="showProcess" CommandArgument='<%#Eval("ItemId") %>' /> </div> </div> </ItemTemplate> </asp:DataList>(2)cs:
void dlServiceItem_ItemDataBound(object sender, DataListItemEventArgs e) { ServiceItem objItem = (ServiceItem)e.Item.DataItem; HyperLink hlAttach = (HyperLink)e.Item.FindControl("hlAttach"); HyperLink hlFlow = (HyperLink)e.Item.FindControl("hlFlow"); Button btnProcess = (Button)e.Item.FindControl("btnProcess"); hlAttach.Enabled = false; hlFlow.Enabled = false; btnProcess.Enabled = false; if (objItem.IsAttach > 0) { hlAttach.Enabled = true; } if (objItem.IsFlow > 0) { hlFlow.Enabled = true; } if (objItem.ApplyMode != (int)EnumServiceItemApplyMode.None) { btnProcess.Enabled = true; } if (hlAttach.Enabled) { hlAttach.Attributes.Add("onmouseover", "btnMouseover(this);"); hlAttach.Attributes.Add("onmouseout", "btnMouseout(this);"); hlAttach.Attributes.Add("onclick", string.Format("attachDownload('{0}'); return false;", objItem.ItemId)); } else { hlAttach.CssClass = "serviceItem_ButtonDisable"; } if (hlFlow.Enabled) { hlFlow.Attributes.Add("onmouseover", "btnMouseover(this);"); hlFlow.Attributes.Add("onmouseout", "btnMouseout(this);"); hlFlow.Attributes.Add("onclick", string.Format("flowView('{0}'); return false;", objItem.ItemId)); } else { hlFlow.CssClass = "serviceItem_ButtonDisable"; } if (btnProcess.Enabled) { btnProcess.Attributes.Add("onmouseover", "btnMouseover(this);"); btnProcess.Attributes.Add("onmouseout", "btnMouseout(this);"); } else { btnProcess.CssClass = "serviceItem_ButtonDisable"; } } void dlServiceItem_ItemCommand(object source, DataListCommandEventArgs e) { try { string strItemId = e.CommandArgument.ToString(); if (e.CommandName=="showProcess") { ServiceItem objItem = BaseBLLFactory.CreateService<ServiceItemService>().GetServiceItem(strItemId); if (objUser == null) { alertLogin.Attributes.Add("style", "display:block;"); } else { string itemUrl = objItem.ApplyUrl; if (objItem.ApplyMode == (int)EnumServiceItemApplyMode.EnterprisePlat) { if (string.IsNullOrEmpty(objItem.ApplyUrl)) { itemUrl = "/psp/Index.aspx"; } } //Response.Write("<script>window.open('" + itemUrl + "','_blank')</script>");//原窗口保留,另外新增一个新页面; Response.Redirect(itemUrl); //Server.Transfer(itemUrl); } } } catch (Exception err) { ShowMessage(err.Message); } }
0 0
- GridView的RowCommand事件和DataList的ItemCommand事件
- GridView的RowCommand事件和DataList的ItemCommand事件
- DataList.ItemCommand 事件
- vs2005中gridview的RowCommand事件
- vs2005中gridview的RowCommand事件
- GridView使用之RowCommand事件的使用
- GridView 中RowCommand 事件的好方法
- 开发花絮:一个DataList的ItemCommand事件意外
- repeat 的两个事件ItemDataBound和ItemCommand
- Repeater 控件的 ItemCommand 事件
- Gridview的RowCommand事件中获取RowIndex的方法
- GridView的RowCommand事件响应得到行索引号
- GridView的RowCommand事件中取得行索引
- GridView中的RowCommand与Sorting事件的一些问题
- GridView.RowCommand 事件中获取当前行的信息
- GridView的RowCommand事件中取得行索引
- GridView的RowCommand事件中取得行索引 技巧
- GridView.RowCommand 事件获取主键值的方法
- 中文域名怎样做虚拟配置?虚拟主机主机无法识别中文域名的解决办法?
- 【Android笔记】各个屏幕的logo尺寸要求
- 分布式缓存-Memcached
- twisted Deferred學習筆記一
- 解决SQL_Server2000“以前的某个程序安装已在安装计算机上创建挂起的文件操作。安装程序前必须重新启动计算机”
- GridView的RowCommand事件和DataList的ItemCommand事件
- nginx+fastcgi 實現多django站點應用
- hadoop 在 centos 6.5 安装指导
- 一点论文写作心得
- SVN分支与合并
- 安卓初学 启动程序欢迎界面
- SEM相关简称
- 【周报】第七周(8月17日~8月23日)工作总结报告——移动应用端
- 问题:关于贴友一个用js传递value默认值的简单实现