Click here to Skip to main content
15,314,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,,


I created a grid view from code behind

My requirement is based on selection list i need to create that no of gridviews
for example my selection is 2 i need to create two gridview .this is sample code i created no of gridviews thats fine

now the problem is here the user enters some values in each gridview

i want to save those gridview data into database.
please help me

Thanks in Advance

VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnbackupsheet.Click
       Dim totalcount = CheckBoxList1.Items.Cast(Of ListItem)().Where(Function(item) item.Selected).Count()
       Dim NumberOfGrids As Integer = totalcount
       For i As Integer = 0 To NumberOfGrids - 1
           Dim ds As New DataSet
           ds = Session("query31ds")
           Dim dt1 As New DataTable
           dt1 = ds.Tables(0)
           Dim gv As New GridView()
           gv.AutoGenerateColumns = False
           Dim bf As New BoundField
           bf.HeaderText = "Name"
           bf.DataField = "Name"
           gv.Columns.Add(bf)
           Dim createStartDate As New Date(Now.Year, Now.Month, 1)
           Dim count = dt1.Columns.Count
           For j = 1 To count - 1
               ' Here is template column portion
               Dim TmpCol As New TemplateField()
               Dim date1 As Date
               date1 = createStartDate.AddDays(j - 1).ToShortDateString()
               TmpCol.HeaderText = date1.ToString("dd-MMM")
               TmpCol.ItemTemplate = New TemplateHandler()
               gv.Columns.Add(TmpCol)
           Next
           gv.DataSource = Session("query31ds")
           gv.DataBind()
           GridviewsContainer.Controls.Add(gv)


       Next
   End Sub
Posted
Comments
snehal harawande 22-Mar-13 4:51am
   
Scenario is not clear. Please give details like
1) Both grid contains same kind of data?
2) Does data needs to saved in same table?
jagadishanil 22-Mar-13 8:48am
   
Thanks For Reply,
The Scenario is:

1)First on pageload i pull some data and added to gridview(which is static created in aspx form)
2)There is a checkboxlist control
3)If I selected 3 items in checkboxlist i need to generate 3 gridviews(this gridview contains textbox) so thats why i am generating from codebehind
4)so now user enter some data in gridview texboxes
5)then submit the form(on this submit click i need to save all the data from gridview to database in onetable only)

The generated gridview having textboxes,
all the gridview having different data

yes saved in same table(ie need to convert gridview columns to rows in database)

1 solution

Simply gather data from different grids & then insert in the db table.
   
Comments
jagadishanil 24-Mar-13 6:58am
   
How...here idont have gridview id, txtbox id how can i

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900