突出asp.net gridview的一排模板按一下按钮 [英] Highlighting a row in asp.net gridview on click of template button

查看:117
本文介绍了突出asp.net gridview的一排模板按一下按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我甲肝,我已经构建这样一个asp.net网格视图。

I hav an asp.net grid view that i have structured like this..

<asp:GridView ID="gridContractor" runat="server" AllowPaging="True" AllowSorting="True"
                AutoGenerateColumns="False" CssClass="GridViewStyle" GridLines="None" EnableModelValidation="True"
                DataKeyNames="DeviceID" OnRowCommand="gridContractor_RowCommand" OnPageIndexChanging="gridContractor_PageIndexChanging"
                Width="100%" EmptyDataText = "No records to display">
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:BoundField HeaderText="Device IMEI" DataField="DeviceID" Visible="false">
                        <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                        <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="175" />
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Person Name" DataField="PersonName">
                        <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                        <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField HeaderText="#Observations" DataField="GpsPointsCount" ControlStyle-Width="50px">
                        <HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" />
                        <ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="50" />
                    </asp:BoundField>
                    <asp:BoundField HeaderText="#Violations" DataField="ViolationCount" ControlStyle-Width="60px">
                        <HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" />
                        <ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="60" />
                    </asp:BoundField>
                    <asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="50">
                        <ItemTemplate>
                            <asp:Button ID="btnEdit" runat="server" Text="View" CommandName="View" Enabled="true"
                                CommandArgument="<%#Bind('DeviceID') %>" />
                        </ItemTemplate>
                        <HeaderStyle Width="50" />
                        <ItemStyle HorizontalAlign="Center"></ItemStyle>
                    </asp:TemplateField>
                </Columns>
                <RowStyle CssClass="RowStyle" />
                <EmptyDataRowStyle CssClass="EmptyRowStyle" />
                <PagerStyle CssClass="PagerStyle" />
                <SelectedRowStyle CssClass="SelectedRowStyle" />
                <HeaderStyle CssClass="HeaderStyle" />
                <EditRowStyle CssClass="EditRowStyle" />
                <AlternatingRowStyle CssClass="AltRowStyle" />
            </asp:GridView>

尽管我已经指定的

&LT; SelectedRowStyle的CssClass =SelectedRowStyle&GT; 这是一个外部CSS我不能够看到所选行背景颜色变化

even though i have specified the <SelectedRowStyle CssClass="SelectedRowStyle"> which is an external Css i am not able to see changes in the selected row background color

我ASLO试着这样做&LT; SelectedRowStyle背景色=艾莉斯蓝/&GT; 仍然没有变化
可一些身体告诉我这是为什么不工作?

i aslo tried doing this <SelectedRowStyle BackColor="AliceBlue" /> and still no changes can some body tell me why this is not working?

推荐答案

从code你发布你无处选择行。你有,如果你想这样做的 SelectedRowStyle 得到应用。

From the code you posted you are nowhere selecting a row. You have to do it if you want the SelectedRowStyle to be applied.

有几种方法可以选择行:

There are several ways you can select a row :


  • 使用按钮/图像/链路与的CommandName =选择

  • 通过设置网格视图的SelectedIndex 从code背后手动处理。

  • Using a button/image/link with CommandName="Select"
  • Handle it manually by setting the grid view SelectedIndex from code behind.

例如在一行命令处理程序 gridContractor_RowCommand 你可以写:

For example in your row command handler gridContractor_RowCommand you can write :

protected void gridContractor_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
    [...]
    GridViewRow selectedRow = (GridViewRow((Button)e.CommandSource).NamingContainer;
    int intRowIndex = Convert.ToInt32(selectedRow.RowIndex);
    gridContractor.SelectedIndex = intRowIndex 
    [...]
}

这篇关于突出asp.net gridview的一排模板按一下按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆