GridView data row vertical align
gridview can show database table data as a tabular representation. gridview has header, footer, data rows to hold columns,
rows and pager. data rows show the actual database table data. we can change the data rows vertical align by assigning gridview
row style vertical align property. we also can change it's value top or bottom programmatically. this example show you
how can we change the gridview data row vertical align programmatically. example also create a sqldatasource to populate gridview.
GridViewRowVerticalAlign.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
GridView1.RowStyle.VerticalAlign = VerticalAlign.Bottom ;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>How to set change GridView data row vertical align programmatically in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy; font-style:italic;">GridView Example: Change Data Row Vertical Align</h2>
<asp:SqlDataSource
ID="SqlDataSource2"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="Select ProductID, ProductName, UnitPrice From Products"
CancelSelectOnNullParameter="false"
>
</asp:SqlDataSource>
<asp:GridView
ID="GridView1"
runat="server"
DataSourceID="SqlDataSource2"
AllowPaging="true"
BackColor="Olive"
ForeColor="Snow"
BorderColor="Orange"
Font-Names="Comic Sans MS"
AutoGenerateColumns="false"
PageSize="7"
Width="500"
>
<RowStyle Height="50" BorderColor="DarkOliveGreen" />
<PagerStyle
BackColor="Crimson"
ForeColor="Snow"
Height="35"
Font-Size="Large"
HorizontalAlign="Right"
/>
<HeaderStyle
BackColor="DarkOliveGreen"
Font-Italic="false"
Height="35"
ForeColor="Snow"
BorderColor="Olive"
/>
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="Product ID" ReadOnly="true" />
<asp:BoundField DataField="Productname" HeaderText="Product Name" />
<asp:BoundField DataField="UnitPrice" HeaderText="Unit Price" />
</Columns>
</asp:GridView>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Change Row Vertical Align Bottom"
Font-Bold="true"
Height="45"
ForeColor="Crimson"
OnClick="Button1_Click"
/>
</div>
</form>
</body>
</html>

