how can i have this griedview show in page while runing withot binding to db

Posted by Shanky11 under VB.NET on 3/6/2013 | Points: 10 | Views : 803 | Status : [Member] | Replies : 2
---------------This is Griedview----------------i need to show it in run page for demo without binding to database

<asp:GridView ID="contactgrdview" runat ="server" AutoGenerateColumns="false" AllowPaging ="true">
<Columns>

<asp:BoundField DataField="username" HeaderText="Name" />
<asp:BoundField DataField ="Mobile" HeaderText ="Mobile-No" />

<asp:TemplateField HeaderText ="Select">

<ItemTemplate >
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>




Responses

Posted by: Satyapriyanayak on: 3/6/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication16.WebForm2" %>

<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="contactgrdview" runat ="server" AutoGenerateColumns="false" AllowPaging ="true">
<Columns>

<asp:BoundField DataField="username" HeaderText="Name" />
<asp:BoundField DataField ="Mobile" HeaderText ="Mobile-No" />

<asp:TemplateField HeaderText ="Select">

<ItemTemplate >
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</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;

namespace WebApplication16
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

DataTable table1 = null;
table1 = new DataTable("Employees");
DataRow row1 = null;
DataColumn username = new DataColumn("username");
table1.Columns.Add(username);

DataColumn Mobile = new DataColumn("Mobile");
table1.Columns.Add("Mobile");


row1 = table1.NewRow();
row1["username"] = "Amit";
row1["Mobile"] = "65464565466";

table1.Rows.Add(row1);

row1 = table1.NewRow();
row1["username"] = "Rahul";
row1["Mobile"] = "456456456";

table1.Rows.Add(row1);

row1 = table1.NewRow();
row1["username"] = "Sachin";
row1["Mobile"] = "6554655456";

table1.Rows.Add(row1);

DataSet ds = null;
ds = new DataSet();
ds.Tables.Add(table1);
contactgrdview.DataMember = "Employees";
contactgrdview.DataSource = ds;
contactgrdview.DataBind();
}
}
}


If this post helps you mark it as answer
Thanks

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 3/6/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Vb.net

Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq

Namespace WebApplication16
Public Partial Class WebForm2
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)

Dim table1 As DataTable = Nothing
table1 = New DataTable("Employees")
Dim row1 As DataRow = Nothing
Dim username As New DataColumn("username")
table1.Columns.Add(username)

Dim Mobile As New DataColumn("Mobile")
table1.Columns.Add("Mobile")


row1 = table1.NewRow()
row1("username") = "Amit"
row1("Mobile") = "65464565466"

table1.Rows.Add(row1)

row1 = table1.NewRow()
row1("username") = "Rahul"
row1("Mobile") = "456456456"

table1.Rows.Add(row1)

row1 = table1.NewRow()
row1("username") = "Sachin"
row1("Mobile") = "6554655456"

table1.Rows.Add(row1)

Dim ds As DataSet = Nothing
ds = New DataSet()
ds.Tables.Add(table1)
contactgrdview.DataMember = "Employees"
contactgrdview.DataSource = ds
contactgrdview.DataBind()
End Sub
End Class
End Namespace

If this post helps you mark it as answer
Thanks

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response