C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

gridview???


Posted Date: 10 Jan 2009      Posted By: kalaiselvi      Member Level: Silver     Points: 1   Responses: 1



I had a tables for productnames and their quantities.(eg.product name sugar,quantities .5 kg,1 kg,10 kg).i want to display the details in the grid as follows
product name quntity(in dropdown).

when i click quantity the price will be displaed in another label.

how can i do this?

suggestions please.
thanks in advance..
kalai





Responses

Author: Murugan    10 Jan 2009Member Level: GoldRating: 2 out of 52 out of 5     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



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Ajax extender.
Previous : How to design a row of tabs,Such they can scroll horizontaly when mouse goes to last one.
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use