I가 내가 어떤 내용을 표시하기 위해 사용하는 오전의 GridView : 당신이 할 수어떻게 내용에 맞게 테이블 셀 크기를 조정하려면
다음 표시하는
<asp:GridView ID="GridView1" AllowSorting="True" OnSorting="GridView1_Sorting" ClientIDMode="Static" runat="server" AutoGenerateColumns="False" EmptyDataText="No PDF was generated" OnRowCreated="GridView1_RowCreated">
<Columns>
<asp:BoundField DataField="Text" HeaderText="File Name" SortExpression="FileName" >
<HeaderStyle Width="15%" />
</asp:BoundField>
<asp:BoundField DataField="Value" HeaderText="File Modified Date" SortExpression="FileDate" >
<HeaderStyle Width="25%" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" Text="Download" runat="server" CommandArgument='<%# Container.DataItemIndex %>' OnClick="DownloadFile" />
</ItemTemplate>
<HeaderStyle Width="15%" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkView" Text="View in Browser" CommandArgument='<%# Container.DataItemIndex %>' OnClientClick="window.document.forms[0].target='blank';" runat="server" OnClick="ViewFile" />
</ItemTemplate>
<HeaderStyle Width="35%" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton runat="server" ToolTip="Delete File" ID="lnkDelete" OnClientClick="confirmUser()" OnClick="DeleteFile" CommandArgument='<%# Container.DataItemIndex %>' ImageUrl="~/delete.png" Width="50px" Height="50px" />
</ItemTemplate>
<HeaderStyle Width="15%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
을 두 번째 및 네 번째 열이 너무 작습니다 참조하십시오. 그래서 다음 코드 숨김을 추가하여 문제를 해결했습니다.
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
TableCell cell0 = e.Row.Cells[0];
cell0.Width = new Unit("35%");
TableCell cell1 = e.Row.Cells[1];
cell1.Width = new Unit("20%");
TableCell cell2 = e.Row.Cells[2];
cell2.Width = new Unit("15%");
TableCell cell3 = e.Row.Cells[3];
cell3.Width = new Unit("15%");
TableCell cell4 = e.Row.Cells[4];
cell4.Width = new Unit("15%");
}
}
결과는 여전히 동일합니다. 내용을 올바르게 표시 할 수 있도록 첫 번째 열이 작고 두 번째 열 및 네 번째 열이 늘어나도록 코드를 수정/추가하려면 어떻게합니까?
은'header' 크기를 조절 모든 하위 행을 변경하지 않는가요? 적어도 HTML에서는 ... – SearchForKnowledge
죄송합니다. 그 질문을 다시 말하면, 이해하는데 어려움이 있습니다. 감사. – aguertin
머리글 행의 크기를 조정하지 않고 (내가 수행하고있는 작업) 아마도 후속 행이 같은 크기가됩니까? – SearchForKnowledge