Showing posts with label GridView. Show all posts
Showing posts with label GridView. Show all posts

Friday, 17 April 2015

How to get / fetch data from GridView and store in DataTable Dynamically in ASP.NET using C#.NET?

How to get / fetch data from GridView and store in DataTable Dynamically in ASP.NET using C#.NET?

In this article I will explain how to fetch / get data from a GridView and how to store it into a DataTable dynamically using C#.NET in ASP.NET

Fallow the below steps:

First, we have to create GridView with required Columns and set its AutoGenerateColumns property to False. If you required footer then show footer is true otherwise false and same as paging also.

Design the GridViewas per your reqirements. Use Templates like Item Template, Edit Item Template, and Footer Templates to Create GridView.

How to fetch data from GridView and store in DataTable?

How to fetch data from GridView and store in DataTable in ASP.NET?

In this article I will explain how to fetch data from a GridView and how to store it into a DataTable in ASP.NET

Fallow the below steps:

First, we have to create GridView and set its AutoGenerateColumns property to False.

Design the GridViewas per your reqirements. Use Templates like Item Template, Edit Item 
Template, and Footer Templates to Create GridView.


How to bind DataTable data to Gridview using C#.NET with ASP.NET Dynamically.

How to bind DataTable data to Gridview using C#.NET with ASP.NET Dynamically.

In this article I will explain how to create DataTable and how to bind DataTable data to Gridview Using C#.NET.

To bind DataTable data to gridview we need to write the code like as shown below like ….

<div><asp:GridView ID=" GridView1" runat="server"></asp:GridView></div>

Add below namespaces in code behind…

using System.Data;

 protected void Page_Load(object sender, EventArgs e)
{
BindDataTabelToGridviewData();
}

/// <summary>
/// Dynamically create DataTable & bind data to gridview
/// </summary>

protected void BindGridviewData()
{
        DataTable dtDynamic = new DataTable();

       DataColumn dc = new DataColumn();

        dc = new DataColumn();
        dc.ColumnName = "MatTransSlNo";
        dc.DataType = Type.GetType("System.String");
        dtDynamic.Columns.Add(dc);

        dc = new DataColumn();
        dc.ColumnName = "Amount";
        dc.DataType = Type.GetType("System.Decimal");
        dtDynamic.Columns.Add(dc);

        dc = new DataColumn();
        dc.ColumnName = "DeleteFlag";
        dc.DataType = Type.GetType("System.Int32");
        dtDynamic.Columns.Add(dc);

dtDynamic.Rows.Add(“1”, 101.10,1);
dtDynamic.Rows.Add(“2”, 102.10,0);
dtDynamic.Rows.Add(“3”, 103.10,1);
dtDynamic.Rows.Add(“4”, 104.50,1);

GridView1.DataSource = dtDynamic;
GridView1.DataBind();
}

Wednesday, 17 September 2014

How to Identify GridView EmptyDataTemplate in JavaScript using ASP.NET. (OR) How to calculate GridView EmptyDataTemplate Textbox values in JavaScript using ASP.NET

In this article I will explain how to Identify GridView EmptyDataTemplate in JavaScript using ASP.NET.

(OR)

How to calculate GridView EmptyDataTemplate Textbox values in JavaScript using ASP.NET

I have created GridView with Empty data template. I want to calculate data dynamically at the data entry time. If the end user enter the Quantity, Rate, TaxAmt after automatically calculate and update the Amount column.

Below is the sample code for design of GridView

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowFooter="true"  Width="100%" >
                                              
              <EmptyDataTemplate>
                                                    <table border="1">
                                                        <tr>                                                           
                                                            <td>Quantity
                                                            </td>
                                                            <td>Rate
                                                           </td>
                                                            <td>TaxAmt
                                                            </td>
                                                            <td>Amount
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                               
                                                            <td Width="10%">
                                                                <asp:TextBox runat="server" ID="txtQuantityEDT" Width="90%" onblur="ValidateGridEmptyTemp();" ></asp:TextBox>
                                                            </td>
                                                            <td Width="10%">
                                                                <asp:TextBox runat="server" ID="txtRateEDT" Width="90%"  onblur="ValidateGridEmptyTemp();"></asp:TextBox>
                                                            </td>
                                                            <td Width="10%">
                                                                <asp:TextBox runat="server" ID="txtTaxAmtEDT" Width="90%" onblur="ValidateGridEmptyTemp();"></asp:TextBox>
                                                            </td>
                                                            <td Width="10%">
                                                                <asp:TextBox runat="server" ID="txtAmountEDT" Width="90%" onblur="ValidateGridEmptyTemp();"></asp:TextBox>
                                                                
                                                            </td>
                                                        </tr>
                                                    </table>
                     </EmptyDataTemplate>
  </asp:GridView>


Below is the JavaScript code for Dynamic empty data template calculation.

function ValidateGridEmptyTemp() {

            var txtName = document.getElementById('<%=((TextBox)GridView1.Controls[0].Controls[0].FindControl("txtQuantityEDT")).ClientID %>');
            var Quantity = document.getElementById('<%=((TextBox)GridView1.Controls[0].Controls[0].FindControl("txtRateEDT")).ClientID %>');
            var Bill = document.getElementById('<%=((TextBox)GridView1.Controls[0].Controls[0].FindControl("txtTaxAmtEDT")).ClientID %>');

            var Final = Number(txtName.value * Quantity.value) + Number(Bill.value);

            document.getElementById('<%=((TextBox)GridView1.Controls[0].Controls[0].FindControl("txtTaxAmtEDT")).ClientID %>').value = Final;

        }