hello sir/mam
i want to add checkbox feild at run time in datagridview. iwant to display datatable value with checkbox in grid view. my code is
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Partial Class _Default
Inherits System.Web.UI.Page
Dim con As SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim rst1, rst2, rst3, dt As New DataTable
Dim cm As SqlCommand
Dim cmbd As SqlCommandBuilder
Dim rs1 As MsgBoxResult
Dim dr, dr1 As DataRow
Dim ip, url1 As String
Dim i, c, q, j, trans, p, rowcnt As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con = New SqlConnection("Data Source=.;Initial Catalog=appraisal;User ID=sa;Password=database")
con.Open()
getques()
End Sub
Public Sub getques()
cm = New SqlCommand("SELECT o.option_id,q.ques_id, q.ques_txt, o.option_txt FROM ques_mst q INNER jOIN option_mst o ON q.ques_id = o.ques_id ", con)
da = New SqlDataAdapter(cm)
cmbd = New SqlCommandBuilder(da)
ds = New DataSet
da.Fill(ds, "q1")
dt = New DataTable
dt = ds.Tables("q1")
dg_ques.DataSource = ds.Tables("q1")
dg_ques.DataBind()
rst3 = New DataTable
rst3.Columns.Add("quesid")
rst3.Columns.Add("questxt")
rst3.Columns.Add("op1")
rst3.Columns.Add("opt2")
rst3.Columns.Add("opt3")
rst3.Columns.Add("opt4")
rst3.Columns.Add("opt5")
cm = New SqlCommand("select * from ques_mst order by queS_id", con)
da = New SqlDataAdapter(cm)
ds = New DataSet
da.Fill(ds, "ques")
rst1 = New DataTable
rst1 = ds.Tables("ques")
If rst1.Rows.Count > 0 Then
i = rst1.Rows.Count
c = 0
While c < i
cm = New SqlCommand("select * from option_mst where queS_id = '" & rst1.Rows(c).Item("ques_id") & "'", con)
da = New SqlDataAdapter(cm)
ds = New DataSet
da.Fill(ds, "opt")
rst2 = New DataTable
rst2 = ds.Tables("opt")
If rst2.Rows.Count > 0 Then
p = rst2.Rows.Count
q = 0
rowcnt = rst3.Rows.Count
rst3.Rows.Add()
rst3.Rows(rowcnt).Item(0) = rst1.Rows(c).Item(0).ToString
rst3.Rows(rowcnt).Item(1) = rst1.Rows(c).Item(1).ToString
While q < p
rst3.Rows(rowcnt).Item(q + 2) = rst2.Rows(q).Item(2).ToString
q = q + 1
End While
End If
c = c + 1
End While
End If
dt = New DataTable
dt = rst3
c = 0
j = 0
While c <= rst3.Rows.Count - 1
Me.dg_ques.Rows(c).Cells(0).Text = rst3.Rows(c).Item(0).ToString
Me.dg_ques.Rows(c).Cells(1).Text = rst3.Rows(c).Item(1).ToString
p = rst3.Columns.Count
q = 2
While q < p - 1
Me.dg_ques.Rows(c).Cells(q).Text = rst3.Rows(c).Item(q).ToString
q = q + 1
End While
c = c + 1
End While
con.Close()
End Sub
Protected Sub grid_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim chk As CheckBox = DirectCast(e.Row.FindControl("checkBoxID"), CheckBox)
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
End Class
here four feild option1,2,3,4 these are fetching the data from database in grid view.
i want that when i run this page then with these option there will be check box are also dispay with each option .
plz help me
this will show like