c# - 如何停止 gridview 在 asp.net 中创建一个 div

标签 c# asp.net html

我有以下 asp.net 代码,它动态生成一个 listitem 并用包含 gridview 的面板填充它:

            Panel panBlocks = new Panel();
            panBlocks.ID = "PanBlockQuestionID" + recordcount.ToString();
            panBlocks.Width = 1300;
            panBlocks.Height = 100;
            panBlocks.BackColor = System.Drawing.ColorTranslator.FromHtml("#fabb3d");

            GridView gvEmployee = new GridView();
            gvEmployee.ID = "gvEmployees" + recordcount.ToString();
            gvEmployee.AutoGenerateColumns = true;
            gvEmployee.DataSource = dtBlocks;
            gvEmployee.DataBind();
            gvEmployee.Style.Add("position", "relative");
            panBlocks.Controls.Add(gvEmployee);

它生成 gridview 但将其包装在一个 div 中。我如何阻止它生成 div,因为它弄乱了样式。它生成的 html 是:

<li id="CPH_Body_liQuestions3" class="liQuestions" style="height:40px;" myCustomIDAtribute="3"><a></a><input type="image" name="ctl00$CPH_Body$lblImg3" id="CPH_Body_lblImg3" class="liQuestionsLabel2" src="../../Images/gtk_cancel.png" style="width:30px;" /><input type="image" name="ctl00$CPH_Body$lblImg3" id="CPH_Body_lblImg3" class="liQuestionsLabel2" src="../../Images/phone_book_edit.png" style="width:30px;" /><span id="CPH_Body_lblID3" class="liQuestionsLabel" style="display:inline-block;width:35px;">298,</span><span id="CPH_Body_lblQuestionType3" class="liQuestionsLabel" style="display:inline-block;width:25px;">1, </span><span id="CPH_Body_lblMsgPrompt3" class="liQuestionsLabel" style="display:inline-block;width:300px;">Fit nylon spacer BG502 to tray,</span><span id="CPH_Body_lblExpectedResp3" class="liQuestionsLabel" style="display:inline-block;width:100px;">YES,</span><span id="CPH_Body_lblImg3" class="liQuestionsLabel" style="display:inline-block;width:30px;"> img: </span><span id="CPH_Body_lblFailMsg3" class="liQuestionsLabel" style="display:inline-block;width:300px;">Not fitted,</span><span id="CPH_Body_lblRetryMsg3" class="liQuestionsLabel" style="display:inline-block;width:300px;">Retry,</span><span id="CPH_Body_lblStart3" class="liQuestionsLabel" style="display:inline-block;width:10px;">,</span><span id="CPH_Body_lblEnd3" class="liQuestionsLabel" style="display:inline-block;width:10px;">,</span><img id="CPH_Body_lblImg3" class="liQuestionsLabel2" onclick="showPanel(&#39;CPH_Body_liQuestions3&#39;)" src="../../Images/block3.png" style="width:30px;" /><div id="CPH_Body_PanBlockQuestionID3" style="background-color:#FABB3D;height:100px;width:1300px;">
    <div>
        <table cellspacing="0" rules="all" border="1" id="gvEmployees3" style="border-collapse:collapse;position:relative;">
            <tr>
                <th scope="col">B1ID</th><th scope="col">B1IncEx</th><th scope="col">B1Criteria</th>
            </tr><tr>
                <td>3</td><td>EX</td><td>590P</td>
            </tr>
        </table>
    </div>
</div></li>

请问如何停止生成 div,因为我无法对其应用样式。

非常感谢

最佳答案

使用 PlaceHolder而不是 Panel,不同之处在于 PlaceHolder 不会呈现为 div 而 Panel 始终呈现。

PlaceHolder 控件不产生任何可见的输出,仅用作网页上其他控件的容器。

关于c# - 如何停止 gridview 在 asp.net 中创建一个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29669579/

相关文章:

c# - 加入 CSV 文件以查询结果

c# - 收到有关 Excel 文件内容有问题的消息

c# - matweb.com : How to get source of page?

.net - 受ASP.NET编译错误CS0009的困扰

asp.net - 将 Web 应用程序分成多个项目

css - 如何更改 IE 所需元素的默认样式?

html - CSS:断行时向上移动

c# - lambda 函数是否比委托(delegate)/匿名函数更快?

asp.net - 动态压缩时如何修复err_content_decoding_failed?

javascript - Chrome 扩展程序粘贴到输入元素中