C# 销售条目表单的datagridview示例

C# 销售条目表单的datagridview示例,c#,datagridview,C#,Datagridview,我想做一张简单的销售登记表, 首先我想询问发票号码和客户姓名,然后 我想使用datagridview添加的销售条目的下一个详细信息,如: sr.no---Product Name------Price---qty---total 1 Item 1 150.00 2 300.00 2 Item 2 80.00 3 240.00 我想在可编辑行中使用datagridview添加以上详细信息,但需要进行适当的

我想做一张简单的销售登记表, 首先我想询问发票号码和客户姓名,然后 我想使用datagridview添加的销售条目的下一个详细信息,如:

sr.no---Product Name------Price---qty---total

1       Item 1            150.00  2     300.00
2       Item 2            80.00   3     240.00
我想在可编辑行中使用datagridview添加以上详细信息,但需要进行适当的验证

private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
   dataGridView1.CurrentRow.Cells["l_sr"].Value = "1";
}

您能为Web表单应用程序提供帮助吗

您需要一个带有datagridview的表单和一个模型类,以便将数据绑定到gridview

取5个文本框、一个按钮和一个名为myGridView的datagridview

salesformation.cs

public class SalesInformation
{
    public int SerialNo { get; set; }
    public string ProductName { get; set; }
    public decimal Price { get; set; }
    public int Quantity { get; set; }
    public decimal Total { get; set; }
}
    private void submitButton_Click(object sender, EventArgs e)
    {
        List<SalesInformation> sales = new List<SalesInformation>();
        SalesInformation newSales = new SalesInformation();
        newSales.SerialNo = Convert.ToInt32(serailNoTextBox.Text);
        newSales.ProductName = productNameTextBox.Text;
        newSales.Price = Convert.ToDecimal(priceTextBox.Text);
        newSales.Quantity = Convert.ToInt32(quantityTextBox.Text);
        newSales.Total = Convert.ToDecimal(totalTextBox.Text);
        sales.Add(newSales);

        myGridView.DataSource = sales;
    }
单击submit(这里是submitButton)按钮,表单将与模型类绑定,实例将插入到集合(列表或任何IEnumerable泛型集合),该集合将与datagridview的数据源绑定

Form1.cs

public class SalesInformation
{
    public int SerialNo { get; set; }
    public string ProductName { get; set; }
    public decimal Price { get; set; }
    public int Quantity { get; set; }
    public decimal Total { get; set; }
}
    private void submitButton_Click(object sender, EventArgs e)
    {
        List<SalesInformation> sales = new List<SalesInformation>();
        SalesInformation newSales = new SalesInformation();
        newSales.SerialNo = Convert.ToInt32(serailNoTextBox.Text);
        newSales.ProductName = productNameTextBox.Text;
        newSales.Price = Convert.ToDecimal(priceTextBox.Text);
        newSales.Quantity = Convert.ToInt32(quantityTextBox.Text);
        newSales.Total = Convert.ToDecimal(totalTextBox.Text);
        sales.Add(newSales);

        myGridView.DataSource = sales;
    }
private void submitButton_单击(对象发送者,事件参数e)
{
列表销售=新列表();
SalesInformation newSales=新的SalesInformation();
newSales.SerialNo=Convert.ToInt32(serailNoTextBox.Text);
newSales.ProductName=productNameTextBox.Text;
newSales.Price=Convert.ToDecimal(priceTextBox.Text);
newSales.Quantity=Convert.ToInt32(quantityTextBox.Text);
newSales.Total=Convert.ToDecimal(totalTextBox.Text);
销售。添加(新闻销售);
myGridView.DataSource=销售;
}

用于Web表单应用程序

您需要一个带有datagridview的表单和一个模型类,以便将数据绑定到gridview

取5个文本框、一个按钮和一个名为myGridView的datagridview

salesformation.cs

public class SalesInformation
{
    public int SerialNo { get; set; }
    public string ProductName { get; set; }
    public decimal Price { get; set; }
    public int Quantity { get; set; }
    public decimal Total { get; set; }
}
    private void submitButton_Click(object sender, EventArgs e)
    {
        List<SalesInformation> sales = new List<SalesInformation>();
        SalesInformation newSales = new SalesInformation();
        newSales.SerialNo = Convert.ToInt32(serailNoTextBox.Text);
        newSales.ProductName = productNameTextBox.Text;
        newSales.Price = Convert.ToDecimal(priceTextBox.Text);
        newSales.Quantity = Convert.ToInt32(quantityTextBox.Text);
        newSales.Total = Convert.ToDecimal(totalTextBox.Text);
        sales.Add(newSales);

        myGridView.DataSource = sales;
    }
单击submit(这里是submitButton)按钮,表单将与模型类绑定,实例将插入到集合(列表或任何IEnumerable泛型集合),该集合将与datagridview的数据源绑定

Form1.cs

public class SalesInformation
{
    public int SerialNo { get; set; }
    public string ProductName { get; set; }
    public decimal Price { get; set; }
    public int Quantity { get; set; }
    public decimal Total { get; set; }
}
    private void submitButton_Click(object sender, EventArgs e)
    {
        List<SalesInformation> sales = new List<SalesInformation>();
        SalesInformation newSales = new SalesInformation();
        newSales.SerialNo = Convert.ToInt32(serailNoTextBox.Text);
        newSales.ProductName = productNameTextBox.Text;
        newSales.Price = Convert.ToDecimal(priceTextBox.Text);
        newSales.Quantity = Convert.ToInt32(quantityTextBox.Text);
        newSales.Total = Convert.ToDecimal(totalTextBox.Text);
        sales.Add(newSales);

        myGridView.DataSource = sales;
    }
private void submitButton_单击(对象发送者,事件参数e)
{
列表销售=新列表();
SalesInformation newSales=新的SalesInformation();
newSales.SerialNo=Convert.ToInt32(serailNoTextBox.Text);
newSales.ProductName=productNameTextBox.Text;
newSales.Price=Convert.ToDecimal(priceTextBox.Text);
newSales.Quantity=Convert.ToInt32(quantityTextBox.Text);
newSales.Total=Convert.ToDecimal(totalTextBox.Text);
销售。添加(新闻销售);
myGridView.DataSource=销售;
}

谢谢sachin,但我希望这些都在Windows应用程序c#中。你是说Windows窗体应用程序吗?谢谢,它正在工作。。。你能告诉我获取下一个自动编号的访问查询吗?你想在mssql中获取下一个自动递增的id吗?如果是这样,那么您应该发布另一个线程,将此线程标记为答案(如果有帮助)。否则新问题很难在评论中回答。谢谢sachin,但我希望所有这些都在Windows应用程序c#中。NET您是指Windows窗体应用程序吗?谢谢,它正在工作。。。你能告诉我获取下一个自动编号的访问查询吗?你想在mssql中获取下一个自动递增的id吗?如果是这样,那么你应该发布另一个帖子,如果有帮助的话,把这个帖子标记为答案。否则新问题很难在评论中回答。