在Gridview中的选定行中显示按钮 [英] show button in selected rows in Gridview
问题描述
大家好,我有一个应用程序,可以记录对呼叫所做更改的记录历史记录,类似于服务台系统中的记录.我有这个gridview:
< ContentTemplate > ;
< 表 =" 100%" < tr =" top" < td =" center" < asp:GridView id =" runat 服务器" ForeColor #333333" BorderColor =" =" 左侧" PageSize =" 20" GridLines =" =" > 100%" 字体大小 =" 字体名称 =" Verdana" CellPadding =" =" 未找到历史记录" AutoGenerateColumns =" 错误" < FooterStyle =" #5D7B9D" 字体粗体 True" ForeColor =" 白色" 字体大小 =" =" 顶部" HorizontalAlign =" 左" / >
< RowStyle =" #F7F6F3" ForeColor #333333 " HorizontalAlign 左侧" >
< EditRowStyle =" #FFFF80" ">> 跨度>
< SelectedRowStyle =" 错误" >
< PagerStyle =" #284775" ForeColor 白色" HorizontalAlign =" 左侧" >
< HeaderStyle =" #5D7B9D" 字体粗体 True" ForeColor =" 白色" HorizontalAlign =" / < AlternatingRowStyle =" 白色" ForeColor >#284775" / >
< PagerSettings =" NumericFirstLast" >
< EmptyDataRowStyle =" Label_Small_Bold" ForeColor >#C00000" HorizontalAlign =" 居中" >
< 列 >
< asp:BoundField DataField =" HeaderText Auth数字" 只读 =" 真实" 可见 =" >
< HeaderStyle =" 左" / < /asp:BoundField >
< asp:BoundField DataField =" ReadOnly True " >
< HeaderStyle =" 左" / < /asp:BoundField >
< asp:BoundField DataField =" DataFormatString { 0:d}" HeaderText 日期" 只读 =" < HeaderStyle =" 左" / < /asp:BoundField >
< asp:BoundField DataField =" HeaderText 说明" 只读 真实" >
< HeaderStyle =" 左" / < /asp:BoundField >
< asp:BoundField 数据字段 =" HeaderText User " 只读 真实" >
< HeaderStyle =" 左" / < /asp:BoundField >
< asp:TemplateField ShowHeader =" < ItemTemplate >
< asp:Button ID =" runat 服务器" CommandName 选择" 文本 查看" / >
< /ItemTemplate >
< ControlStyle =" Label_Small" / < /asp:TemplateField >
< /列 >
< /asp:GridView >
< /td >
< /tr >
< /table >
< /ContentTemplate >
我想做的是仅在描述"列中的记录开始的行上显示btnViewEmail:已发送电子邮件:主题-..."?我会放置文字...但是这与每条历史记录都不一致.
问题2:单击按钮后,向我显示向用户显示已发送电子邮件的最佳方法是什么?目前,我正在将电子邮件详细信息记录到数据库表中,但是可能有附件作为原始电子邮件的一部分发送了? class ="h2_lin">解决方案
问题1的解决方案:
受保护的 void gvCallHistory_RowDataBound(对象发件人,GridViewRowEventArgs e) { 如果(例如,Row.RowType == DataControlRowType.DataRow) { 字符串 strNotes = DataBinder.Eval(e.Row.DataItem," ).ToString(); 字符串 strDescription = strNotes.Substring( 0 , 10 ); 如果(strDescription == " )((Button)e.Row.FindControl(" )).Visible = true ; 其他((按钮)e.Row.FindControl(" )).Visible = <ContentTemplate> <table width="100%"> <tr valign="top"> <td align="center"> <asp:GridView id="gvCallHistory" runat="server" ForeColor="#333333" BorderColor="Black" HorizontalAlign="Left" PageSize="20" GridLines="Horizontal" Width="100%" Font-Size="X-Small" Font-Names="Verdana" CellPadding="4" EmptyDataText="No History Found" AutoGenerateColumns="False"> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Font-Size="Small" VerticalAlign="Top" HorizontalAlign="Left" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Left" /> <EditRowStyle BackColor="#FFFF80" /> <SelectedRowStyle Font-Bold="False" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Left" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" /> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <PagerSettings Mode="NumericFirstLast" /> <EmptyDataRowStyle CssClass="Label_Small_Bold" ForeColor="#C00000" HorizontalAlign="Center" /> <Columns> <asp:BoundField DataField="AuthNumber" HeaderText="Auth Number" ReadOnly="True" Visible="False"> <HeaderStyle HorizontalAlign="Left" /> </asp:BoundField> <asp:BoundField DataField="HistoryID" ReadOnly="True" > <HeaderStyle HorizontalAlign="Left" /> </asp:BoundField> <asp:BoundField DataField="NoteDate" DataFormatString="{0:d}" HeaderText="Date" ReadOnly="True" > <HeaderStyle HorizontalAlign="Left" /> </asp:BoundField> <asp:BoundField DataField="Note" HeaderText="Description" ReadOnly="True" > <HeaderStyle HorizontalAlign="Left" /> </asp:BoundField> <asp:BoundField DataField="Username" HeaderText="User" ReadOnly="True" > <HeaderStyle HorizontalAlign="Left" /> </asp:BoundField> <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:Button ID="btnViewEmail" runat="server" CommandName="Select" Text="View" /> </ItemTemplate> <ControlStyle CssClass="Label_Small" /> </asp:TemplateField> </Columns> </asp:GridView> </td> </tr> </table> </ContentTemplate>
what i would like to do is just display the btnViewEmail only on rows where there is a record beginning: "Email Sent: Subject - ..." in the Description column? there will be text where I have placed ... but this will not be consistent with each historical record.
Question 2: what is the best method for me to display the sent email to the user once the button is clicked - at present I am logging the email details into the DB table but there maybe attachments sent as part of the original email?解决方案Solution to Question 1:
protected void gvCallHistory_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string strNotes = DataBinder.Eval(e.Row.DataItem, "Note").ToString(); string strDescription = strNotes.Substring(0, 10); if (strDescription == "Email Sent") ((Button)e.Row.FindControl("btnViewEmail")).Visible = true; else ((Button)e.Row.FindControl("btnViewEmail")).Visible = false; } }
这篇关于在Gridview中的选定行中显示按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!