Hi Friends,
I am trying to sort my Organisation Name(Ascending) in Gridview itemtemplate, Dont know how to do please help me as soon as possible.TIA
following is my code.
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div style="color: #20B2AA; font-size: xx-large; font-weight: bold; font-style: normal; text-decoration: underline; font-family: arial,helvetica,sans-serif; text-align:center;">Our Members</div>
<div id="search_Mem">
<asp:TextBox ID="txtSearch" runat="server" Width="300px" height="30px"/>
<asp:LinkButton type="submit" Text="Search" runat="server" class="but" OnClick="Search" />
</div>
<br />
<asp:GridView ID="Grid_Members" runat="server" AllowPaging="False"
AllowSorting="True" AutoGenerateColumns="False"
Width="1100px" Height="100%" CellPadding="4"
ForeColor="#333333" GridLines="None"
Font-Names="Helvetica Neue,Helvetica,Arial,sans-serif" CssClass="grid">
<Columns>
<asp:TemplateField SortExpression="Details" ItemStyle-HorizontalAlign="center"
ItemStyle-Font-Names="Helvetica Neue, Helvetica, Arial, sans-serif"
HeaderText="Organisation Details">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Org_Name") %>' Font-Bold="true" Font-Size="Larger" ></asp:Label>
<br />
<br /><i class="fas fa-phone" color="gray"></i> <asp:Label ID="Label4" runat="server" CssClass="label" Text='<%# Bind("Org_PhoneNo") %>'></asp:Label>
<br /><span class="font"></span> <asp:HyperLink ID="HyperLink1" CssClass="label" runat="server" Text='<%# Bind("Org_Link") %>' NavigateUrl='<%# Bind("Org_Link") %>'>HyperLink</asp:HyperLink>
</ItemTemplate>
<HeaderStyle Height="40px" HorizontalAlign="center" />
<ItemStyle HorizontalAlign="center" Font-Names="Helvetica Neue,Helvetica,Arial,sans-serif"
Width="800px"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Content>
using System.Data;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
public partial class members : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
//this.BindGrid();
}
}
protected void Search(object sender, EventArgs e)
{
this.BindGrid();
}
private void BindGrid()
{
string constr = ConfigurationManager.ConnectionStrings["CBMIAConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT Org_Logo, Org_Name,Org_PhoneNo,Org_Link FROM Add_Members WHERE Org_Name LIKE '%' + @Org_Name + '%'";
cmd.Connection = con;
cmd.Parameters.AddWithValue("@Org_Name", txtSearch.Text.Trim());
DataTable dt = new DataTable();
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
Grid_Members.DataSource = dt;
Grid_Members.DataBind();
}
}
}
}
}