If you need to set the width of each column in a gridview
control, If the column is just to
display and no editing needed. You can like this,
<asp:TemplateField HeaderText="column Name" SortExpression="fieldname">
<HeaderTemplate>
<div style="text-align:center;background-color:#41627E;color:White;font-size:x-small;font-weight:bold;overflow: hidden;white-space: nowrap;width: 50px;" >column Name</div>
</HeaderTemplate>
<ItemTemplate>
<div style="font-size:xx-small;white-space:nowrap;overflow: hidden;text-align:left;font-weight:600;font-family:Tahoma;width: 50px;" >
<asp:Label ID="lblGridColumnName"
runat="server"
Text='<%# Bind("fieldname")
%>' ></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
But
if there is a editing to be done, you need to do like this,
<asp:TemplateField HeaderText="column Name" SortExpression="fieldname">
<HeaderTemplate>
<div style="text-align:center;background-color:#41627E;color:White;font-size:x-small;font-weight:bold;overflow: hidden;white-space: nowrap;width: 40px;" >column name</div>
</HeaderTemplate>
<ItemTemplate>
<div style="font-size:xx-small;white-space:nowrap;overflow: hidden;text-align:left;font-weight:600;font-family:Tahoma;width: 40px;" >
<asp:Label ID="lblGridColumnName"
runat="server"
Text='<%# Bind("fieldname",
"{0:n0}") %>'></asp:Label>
</div>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtGridColumnName"
runat="server"
Text='<%# Eval("fieldname",
"{0:n0}") %>' Width="50px" CssClass="cssclass" />
</EditItemTemplate>
</asp:TemplateField>
If you need insert a tooltip for each cell inside a
gridview, you need to set each column tooltip. You can do like this,
protected void
gv_DataBound(object sender, EventArgs e)
{
Label lbl
= new Label();
foreach (GridViewRow rv in
gv.Rows)
{
lbl = (Label)rv.FindControl("lblGridColumnName ");
rv.Cells[1].ToolTip = lbl == null ? string.Empty :
lbl.Text;
}
}
No comments:
Post a Comment