Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
Dynamically Create Grid View on another Gridview row Index
Vivek Kumar Vishwas
Nov 16 2017 4:18 AM
208
Reply
Hello Guys !!
Actually my requirement is to creating Gridview dynamically and bind data in grid view and generating another gridview same time on the previous grid view row again and again...
Binding Gridview Dynamically from code Behind In asp.net from database table
Generating another Gridview on from above gridview row index if data find.
My Code.....
<asp:GridView ID="GridView1" runat="server" />
Cs..........
SqlConnection con =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"constr"
].ConnectionString.ToString());
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
GetData();
}
}
private
void
GetData()
{
String query =
"Select * from TopBill where Pid=0"
;
SqlCommand cmd =
new
SqlCommand(query, con);
SqlDataAdapter sda =
new
SqlDataAdapter(cmd);
DataTable dtMasterBill =
new
DataTable();
sda.Fill(dtMasterBill);
if
(dtMasterBill.Rows.Count > 0)
{
GridView1.DataSource = dtMasterBill;
GridView1.DataBind();
}
else
{
// fieldReptr.Visible = false;
}
}
Table ----------
CREATE
TABLE
[dbo].[TopBill](
[srNo] [
int
] IDENTITY(1,1)
NOT
NULL
,
[Pid] [
int
]
NULL
,
[PName] [nvarchar](
max
)
NULL
,
[PDetails] [nvarchar](
max
)
NULL
,
[cId] [
int
]
NULL
,
[Cname] [nvarchar](
max
)
NULL
,
[Cqty] [nvarchar](
max
)
NULL
)
ON
[
PRIMARY
]
GO
SET
IDENTITY_INSERT [dbo].[TopBill]
ON
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(1, 0, N
''
, N
'optional'
, 10, N
'India'
, N
''
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(2, 10, N
'India'
, N
'optional'
, 1010, N
'Delhi'
, N
'1'
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(4, 0, N
''
, N
'optional'
, 11, N
'Uk'
, N
''
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(6, 0, N
''
, N
'optional'
, 12, N
'USA'
, N
''
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(7, 0, N
''
, N
'optional'
, 13, N
'Canada'
, N
''
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(8, 13, N
'Canada'
, N
'optional'
, 1310, N
'Canada-A'
, N
'10'
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(12, 15, N
'America'
, N
''
, 1510, N
'New Jursy'
, N
'10'
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(15, 0, N
''
, N
''
, 16, N
'bihar'
, N
''
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(16, 1010, N
'Delhi'
, N
'optional'
, 101010, N
'Preet Vihar'
, N
'320'
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(9, 13, N
'Canada'
, N
'optional'
, 1311, N
'Canada-B'
, N
'12'
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(10, 0, N
''
, N
''
, 14, N
'Itley'
, N
''
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(11, 0, N
''
, N
''
, 15, N
'America'
, N
''
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(13, 15, N
'America'
, N
''
, 1511, N
'New Jersy'
, N
'10'
)
INSERT
[dbo].[TopBill] ([srNo], [Pid], [PName], [PDetails], [cId], [Cname], [Cqty])
VALUES
(14, 1510, N
'New Jursy'
, N
''
, 151010, N
'Cat'
, N
'12121'
)
SET
IDENTITY_INSERT [dbo].[TopBill]
OFF
Please solve this urgently...
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
How to display docx first page as image in webpage ?
location of installed products in Add and Remove in c#?