asp.net gridview - updatepanel을 사용하여 행당 여러 줄에 바인딩된 데이터 분산 (asp.net gridview - spread bound data across multi lines per row with updatepanel)


문제 설명

asp.net gridview ‑ updatepanel을 사용하여 행당 여러 줄에 바인딩된 데이터 분산 (asp.net gridview ‑ spread bound data across multi lines per row with updatepanel)

그리드뷰 내부에 패널이 있고 행 너비에 대해 '확산'되어야 합니다.

여기에 이미지 설명 입력

패널에 무엇이 있는지 신경쓰지 마십시오. 내가 여기에 보여 주는 것은 단지 내 요구 사항을 시연하기 위한 것입니다...My HTML:

6
<asp:GridView ID="GridView1" runat="server"
    AutoGenerateColumns="False"
    CellPadding="3"
    CssClass="myGrid"
    DataKeyNames="Role_Name">
    <AlternatingRowStyle BackColor="#E6E6E6" />
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:ImageButton ID="imgShow" runat="server" OnClick="Show_Hide_details" BorderStyle="None" BackColor="Transparent" ImageUrl="~/Content/Images/Arrow_Down.png"
                CommandArgument="Show" />
                <asp:Panel ID="pnlRole" runat="server" Style="position: relative;" Visible="false">
                    <asp:Label ID="lblAAA" runat="server" Text="aaa" /><br />
                    <asp:Label ID="lblBBB" runat="server" Text="bbb" /><br />
                    <asp:Label ID="lblCCC" runat="server" Text="ccc" /><br />
                    <asp:Label ID="lblDDD" runat="server" Text="ddd" /><br />
                </asp:Panel>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Role_Name" HeaderText="Name">
            <HeaderStyle Width="100px" />
            <ItemStyle CssClass="myGridItemMaxWidth" HorizontalAlign="Left" Wrap="false" />
        </asp:BoundField>
        <asp:BoundField DataField="Role_Description" HeaderText="Description">
            <HeaderStyle Width="150px" />
            <ItemStyle CssClass="myGridItemMaxWidth" HorizontalAlign="Left" Wrap="false" />
        </asp:BoundField>
    </Columns>
    <HeaderStyle CssClass="myGridHeader" />
    <RowStyle ForeColor="#000066" />
</asp:GridView>

어떤 도움/아이디어/해결책을 주시면 감사하겠습니다.

편집: 내 문제를 더 잘 설명하기 위해 여기에 다른 이미지가 있습니다. 




<hr>




<h2>참조 솔루션</h2>

<h4>방법 1:</h4> <p>It's tough to do that properly inside of a <code>GridView</code> without it becoming unwieldy.</p><p>You would better off with a <code>ListView</code> and using the functionality there.</p><pre><code><asp:ListView ID=

This will unfortunately have an extra <tr>...</tr> for each row. To resolve that, a way you could do this is to use runat="server" for the <tr> in place of the Panel.

<tr id="pnlRole" runat="server" Visible="false">
    <td colspan="3">
        <asp:Label ID="lblAAA" runat="server" Text="aaa" /><br />
        <asp:Label ID="lblBBB" runat="server" Text="bbb" /><br />
        <asp:Label ID="lblCCC" runat="server" Text="ccc" /><br />
        <asp:Label ID="lblDDD" runat="server" Text="ddd" /><br />
    </td>
</tr>

Now in the code‑behind you can reference this

protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    if (e.CommandName == "Toggle")
    {
        HtmlTableRow pnlRole = e.Item.FindControl("pnlRole") as HtmlTableRow;
        pnlRole.Visible = !pnlRole.Visible;

        ImageButton imgShow = e.Item.FindControl("imgShow") as ImageButton;
        if (pnlRole.Visible == true)
            imgShow.ImageUrl="~/Content/Images/Arrow_Down.png";
        else
            imgShow.ImageUrl="~/Content/Images/Arrow_Up.png";
    }
}

방법 2:

Here is what I came up with ‑

On the left is the GridView when all rows are 'closed'. On the right, after 'opening' 2 rows:

enter image description here</p>

Markup:

<form id="form1" runat="server" style="">
    <asp:ScriptManager runat="server"></asp:ScriptManager>
    <table runat="server" style="font‑weight: bold; margin: 0 auto; font‑family: Arial;">
        <tr>
            <td style="text‑align: center; width: 500px; overflow: hidden">
                <asp:GridView ID="grv_Four_Rows" runat="server"
                    AutoGenerateColumns="False" BackColor="black" GridLines="None"
                    CellPadding="3" CssClass="myGrid" DataKeyNames="Test1_First_Name">
                    <HeaderStyle CssClass="myGridHeader" />
                    <RowStyle BackColor="#b5c7de" />
                    <AlternatingRowStyle BackColor="#d1e0e0" />
                    <Columns>
                        <asp:TemplateField>
                            <ItemStyle HorizontalAlign="Left" />
                            <HeaderTemplate>
                                <table>
                                    <tr>
                                        <td style="width: 150px;">First</td>
                                        <td style="width: 150px;">Last</td>
                                    </tr>
                                </table>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <table>
                                    <td>
                                        <asp:UpdatePanel ID="upp_Main_Row" runat="server">
                                            <ContentTemplate>
                                                <asp:Panel runat="server">
                                                    <td>
                                                        <asp:ImageButton ID="imgShow" runat="server" OnClick="Show_Hide_details"
                                                            ImageUrl="~/Content/Images/Arrow_Down.png" CommandArgument="Show" />&nbsp;
                                                    </td>
                                                    <td style="width: 150px"><%# Eval("Test1_First_Name")%></td>
                                                    <td style="width: 150px"><%# Eval("Test1_Last_Name")%></td>
                                                </asp:Panel>
                                            </ContentTemplate>
                                        </asp:UpdatePanel>
                                    </td>
                                </table>

                                <table style="border‑style: solid; border‑width: thin; width: 100%">
                                    <asp:UpdatePanel ID="upp_2nd_row" runat="server" Visible="false">
                                        <ContentTemplate>
                                            <tr>
                                                <td>
                                                    <a style="color: red">Address: </a><%# Eval("Test1_Address")%>
                                                </td>
                                            </tr>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                    <asp:UpdatePanel ID="upp_3rd_row" runat="server" Visible="false">
                                        <ContentTemplate>
                                            <tr>
                                                <td>
                                                    <a style="color: red;">Description: </a><%#Eval("Test1_Description")%>
                                                </td>
                                            </tr>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                    <asp:UpdatePanel ID="upp_4th_row" runat="server" Visible="false">
                                        <ContentTemplate>
                                            <tr style="float: left">
                                                <td>
                                                    <a style="color: red">Note1: </a><%#Eval("Test1_Note_1")%>&nbsp;&nbsp;
                                                    <a style="color: red">Note2: </a><%#Eval("Test1_Note_2")%>
                                                </td>
                                            </tr>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </table>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </td>
        </tr>
    </table>
</form>
<style type="text/css">
    .myGrid {
        border: 1px solid black;
        ‑webkit‑border‑radius: 8px;
        ‑moz‑border‑radius: 8px;
        border‑radius: 8px;
        overflow: hidden;
        background‑color: white;
        text‑align: center;
        margin: 0 auto;
    }

    .myGridHeader > th {
        text‑align: center;
        border: solid 1px;
        font‑family: Arial;
        background‑color: #DDFFD6;
        font‑weight: bold;
        color: #000066;
    }
</style>  

C# code‑behind:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_grv_Four_Rows();
        }
    }
    //================================================================================================
    protected void Show_Hide_details(object sender, EventArgs e)
    {
        ImageButton imgShowHide = sender as ImageButton;
        GridViewRow row = imgShowHide.NamingContainer as GridViewRow;
        if (imgShowHide.CommandArgument == "Show")
        {
            row.FindControl("upp_2nd_Row").Visible = true;
            row.FindControl("upp_3rd_Row").Visible = true;
            row.FindControl("upp_4th_Row").Visible = true;
            imgShowHide.CommandArgument = "Hide";
            imgShowHide.ImageUrl = "~/Content/Images/Arrow_Up.png";
        }
        else
        {
            row.FindControl("upp_2nd_Row").Visible = false;
            row.FindControl("upp_3rd_Row").Visible = false;
            row.FindControl("upp_4th_Row").Visible = false;
            imgShowHide.CommandArgument = "Show";
            imgShowHide.ImageUrl = "~/Content/Images/Arrow_Down.png";
        }
    }
    //================================================================================================
    private void load_grv_Four_Rows()
    {
        try
        {
            SqlConnection con;
            DataSet ds;
            con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["BETSEFER_DB"].ConnectionString);
            string CmdString = "SELECT * FROM tbl_Test1 ORDER BY Test1_First_Name";
            ds = new DataSet();
            using (SqlDataAdapter sda = new SqlDataAdapter(CmdString, con))
            {
                sda.Fill(ds);
                if (ds.Tables.Count > 0)
                {
                    DataView dv = ds.Tables[0].DefaultView;
                    grv_Four_Rows.DataSource = dv;
                    grv_Four_Rows.DataBind();
                }
            }
        }
        catch (SqlException ex)
        {
            Session["mySQL_Error_Msg"] = ex.Message;
            Server.ClearError();
            Response.Redirect("~/Errors.aspx");
        }
    }
    //================================================================================================

The table: enter image description here

I still have lots of formatting and cosmetic issues but for those I'll open a new post. Hope it helps someone.

(by gadiKirkgadi)

참조 문서

  1. asp.net gridview ‑ spread bound data across multi lines per row with updatepanel (CC BY‑SA 2.5/3.0/4.0)

#panel #gridview #multiline #updatepanel #ASP.NET






관련 질문

R을 사용하여 패널 데이터의 마지막 이벤트 이후 실행 계산 (Using R to count a run since last event in panel data)

버튼을 클릭한 후 한 패널을 표시하고 동일한 프레임에서 두 번째 버튼을 클릭하면 다른 패널을 표시합니다. (show one panel after button is clicked and other panel when second button is clicked in the same frame)

외부를 클릭하면 패널을 닫아야 함(초점 상실) (Need To Close A Panel When Clicked Outside (Lost Focus))

asp.net gridview - updatepanel을 사용하여 행당 여러 줄에 바인딩된 데이터 분산 (asp.net gridview - spread bound data across multi lines per row with updatepanel)

문자를 포함하는 고유 식별자와 함께 xtreg 사용 (Using xtreg with unique identifier that includes letters)

matlab SVM은 NaN을 반환합니다. (matlab SVM returns NaN)

특정 형식의 JAVA GUI 제작에 대한 질문 (Question about making a JAVA GUI of a certain format)

슬라이딩 패널 구분선을 사용하여 HTML 페이지를 다른 섹션으로 분할하시겠습니까? 어떻게 이루어지나요? (Splitting HTML page into different sections using sliding panel dividers? How is it done?)

Swift Mac Os 응용 프로그램 - NSSavePanel이 '백그라운드 전용' 응용 프로그램에서 올바르게 작동하지 않습니다. (Swift Mac Os Application - NSSavePanel does not behave correctly with a 'background only' application)

Python 저주 update_panels() 및 Panel.move() 문제 (Python Curses update_panels() and Panel.move() issues)

stargazer를 사용하여 plm FE 회귀에서 전체 R2를 얻는 방법은 무엇입니까? (How to get between and overall R2 from plm FE regression with stargazer?)

Java, 패널용 그래픽 개체 생성 및 편집? (Java, create and edit a Graphics Object for Panel?)







코멘트