| Author: Murugan 10 Jan 2009 | Member Level: Gold | Rating:  Points: 6 |
Check this code ..
its just an example you will get idea from this example..
any thing message me..
//code
<asp:DataList ID="DataList1" runat="server" DataKeyField="Cus_State" OnItemDataBound="DataList1_ItemDataBound" Width="100%"> <ItemTemplate> Customer State : <asp:Label ID="Label1" runat="server" Text='<%# Bind("Cus_State") %>'></asp:Label
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Cus_State,Cus_Code" GridLines="Horizontal" Width="100%" OnRowDataBound="GridView1_RowDataBound" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" OnRowUpdating="GridView1_RowUpdating">
<Columns> <asp:TemplateField> <HeaderTemplate> <asp:CheckBox ID="chkSelectAll" runat="server" Text="Select all" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="chkCusNo" runat="server" /> <asp:HiddenField ID="hidCusState" runat="server" Value='<%# Bind("Cus_State") %>' /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Cus_Name" HeaderText="Name" ></asp:BoundField> <asp:BoundField DataField="Cus_Gender" HeaderText="Gender" ></asp:BoundField> <asp:BoundField DataField="Cus_Age" HeaderText="Age" ></asp:BoundField> <asp:BoundField DataField="Cus_City" HeaderText="City" > </asp:BoundField> <asp:CommandField HeaderText="Edit" ShowEditButton="True" ></asp:CommandField> <asp:CommandField HeaderText="Delete" ShowDeleteButton="True"></asp:CommandField> </Columns> <EmptyDataTemplate> You have deleted all records. </EmptyDataTemplate> </asp:GridView> </ItemTemplate> </asp:DataList>
//steps // Bind the DataList in Form Load Event
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string sql = "Select Distinct Cus_State from Customers”; SqlDataAdapter da = new SqlDataAdapter(sql, “YourConnectionString”); DataTable dt = new DataTable(); da.Fill(dt); DataList1.DataSource = dt; DataList1.DataBind(); } }
//steps for binding private void BindGrid(GridView GridView, string CusState) { string sql = "Select Cus_No, Cus_Name, Cus_Gender, Cus_Age, Cus_City, Cus_State from Customers Where Cus_State='" + CusState+ "'"; SqlDataAdapter da = new SqlDataAdapter(sql, “YourConnectionString”); DataTable dt = new DataTable(); da.Fill(dt); GridView.DataSource = dt; GridView.DataBind(); }
check it and rate this code....
Yours Always..
Murugan
|