I am using a gridview in my application,in gridview i am having textbox which i had created by item template,i am new in programming i have no idea how to populate the data to the gridview,the data should be displayed in the gridview and after that the user had to perform some calculations like :

S.no ServCode ServName Quantity Discount NetAmount


how to populate data in the grid and perform the calculation help to solve the problem...!!!!!!!!!!!!!

what have you tried so far? what kind of errors are you getting?

You can use Eval or Bind display data in the text field. You should past your code so we can help

My Code is:

code In .aspx file  

<div>
     <asp:GridView ID="GridView1" runat="server" Font-Bold="True" ForeColor="#BF6000" Height="191px" Width="600px" AutoGenerateColumns="False" BorderStyle="None" BorderWidth="1px" HorizontalAlign="Justify" OnSelectedIndexChanged="GridView1_SelectedIndexChanged1" OnRowDataBound="GridView1_RowDataBound" onrowcommand="GridView1_RowCommand"> <HeaderStyle BackColor="#FFFFC4" Font-Bold="True" ForeColor="#BF6000" /> <Columns> <asp:TemplateField HeaderText="S.No"> <ItemTemplate> <asp:Label ID="label10" runat="server" Font-Bold="true" ForeColor="#BF6000" Text="<%# Container.DataItemIndex + 1 %>"> </asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Serv Code" > <ItemTemplate> <asp:TextBox ID="TxtServiceCode" Font-Bold="true" ForeColor="#BF6000" Text='<%# Bind("ServiceCode") %>' runat="server" Width="55px"> </asp:TextBox> <asp:Button ID="btninsert" runat="server" BackColor="Ivory" Font-Bold="true" ForeColor="#BF6000" text="Insert" CommandName="Insert" UseSubmitBehavior="false" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name"> <ItemTemplate> <asp:TextBox ID="TxtServiceName" runat="server" ReadOnly="true" Font-Bold="true" ForeColor="#BF6000" Width="150px" Text='<%# DataBinder.Eval(Container, "DataItem.ServiceName") %>'></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Serv Amt"> <ItemTemplate> <asp:TextBox ID="TxtServiceAmount" ReadOnly="true" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.ServiceAmount") %>' runat="server" Width="55px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Qty"> <ItemTemplate> <asp:TextBox ID="Txtquantity" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.Quantity") %>' runat="server" Width="55px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Disc Amt"> <ItemTemplate> <asp:TextBox ID="TxtdiscAmt" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.Discount") %>' runat="server" Width="55px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Net Amt"> <ItemTemplate> <asp:TextBox ID="TxtNetAmt" ReadOnly="true" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.NetAmountPaid") %>' runat="server" Width="55px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> 
    </div>
    <div>
        <asp:Label ID="LblMessage" runat="server" Text=""></asp:Label>

Add code in Code behind  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["test"].ConnectionString);
        SqlCommand comd = new SqlCommand("StoreProcedureName", con);
        comd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter(comd);
        DataTable dt=new DataTable();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        else
        {
            LblMessage.Text = "Sorry no recod";
        }
    }
}

The data is not coming into the gridview i would appreciate if u share your knowledge with me..............!!!!!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.