1

大家好,我需要你的帮助,我手头有一个项目是使用带有向下钻取的网格视图,我必须能够单击一个按钮或在线并向下延伸另一行并提供详细信息,我已经有代码按钮展开和折叠并更改按钮,但不能同时执行这两项操作,这正是我想要的,当我单击“加号”时,该行会展开并在单击时将按钮图像更改为减号和减号为“加号”并折叠详细信息。谢谢 :) 这是 gridview、jquery 和代码隐藏的代码:

Gridview:
    <asp:GridView 
    ID="gvMajor" 
    runat="server" 
    AutoGenerateColumns="False" 
    BackColor="White" 
    BorderColor="Black" 
    BorderStyle="Ridge" 
    BorderWidth="1px" 
    CellPadding="1" 
    onrowdatabound="MyGrid_RowDataBound" 
    onrowcommand="Delete_info" 
    AllowPaging="True" 
    onselectedindexchanging="Edit_info" 
    PageSize="5" 
    Width="100%"  
    onpageindexchanged="GridView1_PageIndexChanged" 
    DataKeyNames="ID" 
    DataSourceID="MajorsDS" 
        onselectedindexchanged="gvMajor_SelectedIndexChanged"  >

    <RowStyle 
        BackColor="#EEEEEE" 
        ForeColor="Black" 
        BorderColor="Black"/>

    <Columns>

        <asp:TemplateField ShowHeader="False">
            <ItemTemplate>
                <asp:ImageButton ID="ImageButton1" runat="server" 
                    CommandName="Expand/Collapse" ImageUrl="~/Images/Expand.png" 
                    Text="Button" CssClass="View"/>
            </ItemTemplate>
        </asp:TemplateField>

        <asp:BoundField DataField="ID" HeaderText="ID" 
            SortExpression="ID" ReadOnly="True" />
        <asp:BoundField DataField="Subject" HeaderText="Subject" 
            SortExpression="Subject" />
        <asp:BoundField DataField="InsertDate" HeaderText="InsertDate" 
            SortExpression="InsertDate" />
        <asp:BoundField DataField="DisabledDate" HeaderText="DisabledDate" 
            SortExpression="DisabledDate" />
        <asp:CommandField ShowSelectButton="True" ButtonType="Image" 
            SelectImageUrl="~/Images/1340789891_gtk-edit.png" />

        <asp:ButtonField ButtonType="Image" CommandName="Delete_info" 
                    ImageUrl="~/Images/1340790235_gnome-fs-trash-empty.png" 
            Text="Button"  />

    </Columns>

<FooterStyle 
    BackColor="#CCCCCC" 
    ForeColor="Black" />

<PagerStyle 
    BackColor="#999999" 
    ForeColor="Black" 
    HorizontalAlign="Center" />

<SelectedRowStyle 
    BackColor="#008A8C" 
    Font-Bold="True" 
    ForeColor="White" />

<HeaderStyle 
    BackColor="#000084" 
    Font-Bold="True" 
    ForeColor="White" />

<AlternatingRowStyle 
    BackColor="Gainsboro" />

</asp:GridView>

Jquery:

    <script type="text/jscript">
    $('.View').click(function()
    {
        $('#details').remove();
        var detailID=$(this).attr('data-id');

        $(this).closest('tr').after('<tr id="details"><td colspan="9"></td></tr>')
        $('#details td').load('Details.aspx?detail='+detailID+' #content');

    });
</script> 

<script type="text/jscript">
    $('.Hide').click(function()
    {
        $('table td img.Hide').click(function(){     $(this).parent().parent().remove(); });
    });
</script> 


Codebehind: 

        protected void Delete_info(object sender, GridViewCommandEventArgs e)
    {
        sqlconn.Open();
        int idx = Convert.ToInt32(e.CommandArgument);
        if (e.CommandName == "Delete_info")
        {
            GridViewRow selectedRow = gvMajor.Rows[idx];
            TableCell ID_info = selectedRow.Cells[2];
            string ID = ID_info.Text;
            //código para descobrir o nome do user introduzido
            string user_status = "Select Status FROM JANELA_CSD_USERS WHERE ID=@ID";
            SqlCommand USTATUS = new SqlCommand(user_status, sqlconn);
            USTATUS.Parameters.AddWithValue("@ID", Convert.ToInt32(ID.ToString()));
            USTATUS.ExecuteNonQuery();
            int User_status = Convert.ToInt32(USTATUS.ExecuteScalar());
            if (User_status == 1)
            {


                SqlCommand sqlcomm = new SqlCommand("UPDATE JANELA_CSD_INFO SET Status=0, DisabledDate=@DisabledDate WHERE ID=@ID", sqlconn);
                sqlcomm.Parameters.Add("@DisabledDate", SqlDbType.SmallDateTime).Value = DateTime.Now.Date;
                sqlcomm.Parameters.Add("@ID", SqlDbType.Int).Value = Convert.ToInt32(ID.ToString());
                sqlcomm.ExecuteNonQuery();

            }
            else
            {
            }
            sqlconn.Close();
        }
        if (e.CommandName == "Expand/Collapse")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow gvrow =gvMajor.Rows[index];
            if (((ImageButton)gvrow.Controls[0].Controls[0]).ImageUrl == "~/Images/1340791822_delete.png")
                ((ImageButton)gvrow.Controls[0].Controls[0]).ImageUrl = "~/Images/1340791835_add.png";
            else
                ((ImageButton)gvrow.Controls[0].Controls[0]).ImageUrl = "~/Images/1340791822_delete.png";
        }
    }
4

0 回答 0