Breaking News

Editors Picks

Showing posts with label Grid View. Show all posts
Showing posts with label Grid View. Show all posts

Friday, July 13, 2012

Get ASP.Net Grid View Row Value and its Row Index when clicked using JavaScript



Introduction

Get ASP.Net Grid View Row Value and its Row Index when clicked using JavaScript

Here I explained how to get the ASP.Net Grid View Row Value and its Row Index client side using JavaScript. He has also explained how we can find the Grid View Cells and the controls value inside the Grid View Template Fields client side using JavaScript.
Description

Below I have a simple ASP.Net Grid View. That content two columns SNo and Name both column are Template Fields.
When any gird View Cell is clicked, then Cell value and cell index value show on Alert box.


Read more ...

in ASP.NET copy cell value from one gridview and paste to another gridview


Introduction

Here I explained how to get and Set the ASP.Net Grid View Row value to other Grid View Row client side using JavaScript. This feature using Click on cell 2 value of grid view and then click on other grid view at any ROW then this value is copy the Second Grid View. And also this process also for second grid copy value from CELL 2 using click on cell then paste this value on first Gird view using click on first gird view.


Read more ...

Thursday, July 5, 2012

How to show gridview header when there is no data or empty in Asp.net


Introdcution

What happens if your grid view  control does not have any records to display? Well, if you set the EmptyDataText or EmptyDataTemplate properties, the grid will show something, only probably not what you'd like - the normal structure, as if it was populated with records. Here's a possible solution
Here I will explain how to display or show grid view header even if grid view does not contain data or show gridview header with no records.

Description

I got requirement like show the grid view header or header with message even if grid view does not contain any data. In our applications we have 3 example who show gird view

Read more ...

Tuesday, July 3, 2012

parameter in sqldatasource with select command

SqlDataSource allows you to Select  the data from the database without even writing a single line of code. But sometimes you need to dynamically assign a parameter. First let's take a look at the  dynamically assign the parameters.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>SqlDatasource select parameterstitle>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 157px;
        }
    style>
head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="style1">
            <tr>
                <td class="style2">
                    User Name
                td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server">asp:TextBox>
                td>
            tr>
            <tr>
                <td class="style2">
                    Password
                td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server">asp:TextBox>
                td>
            tr>
            <tr>
                <td class="style2">
                     
                td>
                <td>
                    <asp:Button ID="btnsubmit" runat="server" Text="Submit" OnClick="btnsubmit_Click" />
                td>
            tr>
            <tr>
                <td colspan="2">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
                        ForeColor="#333333" GridLines="Horizontal" AllowPaging="True" AllowSorting="True"
                        DataSourceID="SqlDataSource1" Width="469px">
                        <RowStyle BackColor="#EFF3FB" />
                        <Columns>
                            <asp:BoundField DataField="username" HeaderText="username" SortExpression="username" />
                            <asp:BoundField DataField="cityname" HeaderText="cityname" SortExpression="cityname" />
                        Columns>
                        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <EditRowStyle BackColor="#2461BF" />
                        <AlternatingRowStyle BackColor="White" />
                    asp:GridView>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                        ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT username,cityname FROM useraccessprofile WHERE UserName = @UserName AND pwd = @pwd ">
                        <SelectParameters>
                            <asp:ControlParameter Name="UserName" ControlID="TextBox1" PropertyName="Text" />
                            <asp:ControlParameter Name="pwd" ControlID="TextBox2" PropertyName="Text" />
                        SelectParameters>
                    asp:SqlDataSource>
                td>
            tr>
            <tr>
                <td class="style2">
                     
                td>
                <td>
                     
                td>
            tr>
        table>
    div>
    form>
body>
html>

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
      
    }
}

Read more ...

Friday, May 25, 2012

Merge GridView Header column in ASP.NET


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestwebPage.aspx.cs" Inherits="TestwebPage" %>

<%@ Register Assembly="Obout.Ajax.UI" Namespace="Obout.Ajax.UI.TreeView" TagPrefix="obout" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title> gridview merge column headers title>
    <script type="text/javascript">
     function Filter(Obj)
     {
        var grid=document.getElementById('GridView');
        var terms = Obj.value;
        var cellNr = "0";//grid colunm cellindex in which you want to search
        var ele;
        for (var r = 1; r < grid.rows.length; r++)
        {
          ele = grid.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g, "");
            if (ele.toLowerCase().indexOf(terms) >= 0)
                grid.rows[r].style.display = '';
            else grid.rows[r].style.display = 'none';
        }
     };   
  
    script>

head>
<body>
    <form id="form1" runat="server">   
<asp:GridView ID="gridView" runat="server" OnRowCreated="gridView_RowCreated">asp:GridView>   
    form>
body>
html>


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Obout.Ajax.UI.TreeView;
using System.Data.SqlClient;
using System.Net.Mail;
using System.IO;
using System.Collections.Generic;


public partial class TestwebPage : System.Web.UI.Page
{
    public enum AnalysisType { sss, ssss };
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridView();
        }
    }

    protected void gridView_PreRender(object sender, EventArgs e)
    {
        MergeRows(gridView);
    } 

    void BindGridView()
    {
        DataSet dataSet = new DataSet();
        gridView.DataSource = dataSet;
        gridView.DataBind();
    }

   protected void gridView_ RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            //custom header.
GridView gvHeader = (GridView)sender;
GridViewRow gvHeaderRow = new GridViewRow(0, 0,    DataControlRowType.Header,DataControlRowState.Insert);
TableCell tcell = new TableCell();

// First column
tcell.Text = "First Column1";
tcell.ColumnSpan = 2;
tcell.BackColor = System.Drawing.Color.DarkGray;
gvHeaderRow.Cells.Add(tcell);

// Second  column
tcell = new TableCell();
tcell.Text = "Second Column2";
tcell.ColumnSpan = 2;
gvHeaderRow.Cells.Add(tcell);

gvHeader.Controls[0].Controls.AddAt(0, gvHeaderRow);

        }
    }}




Read more ...

How to merge cells with equal values in a GridView in Asp.net


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestwebPage.aspx.cs" Inherits="TestwebPage" %> 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>merge row in grid viewtitle>
    <script type="text/javascript">
     function Filter(Obj)
     {
        var grid=document.getElementById('GridView');
        var terms = Obj.value;
        var cellNr = "0";//grid colunm cellindex in which you want to search
        var ele;
        for (var r = 1; r < grid.rows.length; r++)
        {
          ele = grid.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g, "");
            if (ele.toLowerCase().indexOf(terms) >= 0)
                grid.rows[r].style.display = '';
            else grid.rows[r].style.display = 'none';
        }
     };   
  
    script>

head>
<body>
    <form id="form1" runat="server">   
    <asp:GridView ID="gridView" runat=server CellPadding="2" OnPreRender="gridView_PreRender">asp:GridView>
   
    form>
body>
html>


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Net.Mail;
using System.IO;
using System.Collections.Generic;


public partial class TestwebPage : System.Web.UI.Page
{
    public enum AnalysisType { sss, ssss };
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridView();
        }
    }

    protected void gridView_PreRender(object sender, EventArgs e)
    {
        MergeRows(gridView);
    } 

    void BindGridView()
    {
        DataSet dataSet = new DataSet();
        gridView.DataSource = dataSet;
        gridView.DataBind();
    }

    public static void MergeRows(GridView gridView)
    {
     for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
      {
         GridViewRow row = gridView.Rows[rowIndex];
         GridViewRow previousRow = gridView.Rows[rowIndex + 1];

       for (int cellIndex = 0; cellIndex < row.Cells.Count; cellIndex++)
       {
         if (row.Cells[cellIndex].Text == previousRow.Cells[cellIndex].Text)
         {
          row.Cells[cellIndex].RowSpan = previousRow.Cells[cellIndex].RowSpan < 2 ? 2 : previousRow.Cells[cellIndex].RowSpan + 1;
          previousRow.Cells[cellIndex].Visible = false;
         }
        }
      }
    }
} 
Read more ...

Contact Us

Name

Email *

Message *