我正在从数据库中检索一些数据并使用 c# asp.net 在网格视图中进行绑定。首先我想解释我的代码,然后我将解释我的要求。
索引.aspx:
<asp:GridView ID="comnt_Gridview" runat="server" AutoGenerateColumns="false" Width="100%" CssClass="table table-striped table-bordered margin-top-zero" OnRowDataBound="comnt_Gridview_RowDataBound" DataKeyNames="Health_Comment_ID" >
<Columns>
<asp:TemplateField HeaderText="Sl. No" ItemStyle-CssClass="col-md-1 col-sm-1">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
<ItemStyle CssClass="col-md-1 col-sm-1"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Health ID" ItemStyle-CssClass="col-md-1 col-sm-1" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="healthid" runat="server" Text='<%#Eval("Health_ID") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" CssClass="col-md-1 col-sm-1"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" ItemStyle-CssClass="col-md-1 col-sm-1" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="Name" runat="server" Text='<%#Eval("Health_Comment_Name") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" CssClass="col-md-1 col-sm-1"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email" ItemStyle-CssClass="col-md-2 col-sm-2" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="Email" runat="server" Text='<%#Eval("Health_comment_Email") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" CssClass="col-md-2 col-sm-2"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Web Url" ItemStyle-CssClass="col-md-2 col-sm-2" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="Url" runat="server" Text='<%#Eval("Health_Comment_Website") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" CssClass="col-md-2 col-sm-2"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Comments" ItemStyle-CssClass="col-md-3 col-sm-3" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblRemark" runat="server"Text='<%# Eval("Health_Comment_Message").ToString().Length > 100? (Eval("Health_Comment_Message") as string).Substring(0,100) + " ..." : Eval("Health_Comment_Message") %>'ToolTip='<%# Eval("Health_Comment_Message") %> '> </asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" CssClass="col-md-3 col-sm-3">
</ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status" ItemStyle-CssClass="col-md-1 col-sm-1" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<div class="btn-group btn-toggle">
<asp:LinkButton ID="accept" CssClass="btn btn-xs btn-inactive" CommandName="Accept" runat="server" style="padding:1px 2px;" Text="Accept" onclick="accept_click" CommandArgument='<%#Eval("Health_Comment_ID")%>'></asp:LinkButton>
<asp:LinkButton ID="reject" runat="server" Text="Reject" CommandName="Reject" CssClass="btn btn-xs btn-success active" style="padding:1px 2px;" onclick="reject_Click" CommandArgument='<%#Eval("Health_Comment_ID")%>' ></asp:LinkButton>
</div>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" CssClass="col-md-2 col-sm-2"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ItemStyle-CssClass="col-md-2 col-sm-2" >
<ItemTemplate>
<a href="javascript:void(0)" data-toggle="tooltip" title="" class="btn btn-xs btn-success" data-original-title="View" onClick="doctordetailsshowdiv()"><i class="fa fa-eye"></i></a>
</ItemTemplate>
<ItemStyle CssClass="col-md-2 col-sm-2"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
index.aspx.cs:
namespace ODIYA_Doctor_Admin.Module.Front_End_Management
{
public partial class HealthComment : System.Web.UI.Page
{
private healthCommentBL objhealthCommentBL = new healthCommentBL();
protected void Page_Load(object sender, EventArgs e)
{
lbluname.Text = Session["username"].ToString().Substring(0, Session["username"].ToString().IndexOf(' '));
Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
comnt_Gridview.DataSource = objhealthCommentBL.getHealthCommentDetails();
comnt_Gridview.DataBind();
}
protected void comnt_Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
}
}
我正在从数据库中获取字段值。这里Health_Comment_Status
我的要求是在绑定到 gridview 之前,如果Health_Comment_Status
值是R
来自 gridview 的拒绝链接按钮颜色将为红色,否则来自同一网格视图的接受链接按钮颜色将为绿色。类似地在链接按钮的每个单击事件中,我想检查链接按钮的背景颜色,以便我可以更新 DB 中的状态。请帮助我。