0
我需要得到DataKeyNames值Gridview
裏面的linkbutton的點擊事件使用c#。我解釋我的代碼如下。如何獲得使用c#asp.net LinkButton的點擊事件GridView的DataKeyNames值
的Index.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>
<asp:Label ID="Url" runat="server" Text='<%#Eval("Health_Comment_Status") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" CssClass="col-md-1 col-sm-1"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ItemStyle-CssClass="col-md-2 col-sm-2" >
<ItemTemplate>
<div class="pull-left rpaddingdivsmall1"><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>/</div>
<div class="profile_right_side_eidt pull-left">
<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"></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" ></asp:LinkButton>
</div>
</div>
<div class="clearfix"></div>
</ItemTemplate>
<ItemStyle CssClass="col-md-2 col-sm-2"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
在這裏,我需要在用戶點擊任何的LinkButton(i.e. accept/Reject
)相應的按鈕背景色將會改變,並且點擊事件裏面我需要的DataKeyNames
value.Please幫我。
好了,但怎麼能我得到按鈕的ID,以便我可以使其背景顏色。 – satya
@不幸運:你正在談論GridViewName_ItemCommand()事件,但我需要在點擊事件中。 – satya