How to Add Data of different datatypes in same column in datagrid?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strSql As String
Dim i As Integer, totDay As Integer, j As Integer
Dim dtl As New DataTable


totDay = DateDiff(DateInterval.Day, CDate(Me.TextBox1.Text), CDate(Me.TextBox2.Text))
conn.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM Company", conn)
da.Fill(dtl)
Dim xWdtTran As DataTable = New DataTable
xWdtTran.Columns.Add(New DataColumn("cmpid"))
xWdtTran.Columns.Add(New DataColumn("cmpname"))
xWdtTran.Columns.Add(New DataColumn("idcmp"))
Dim tmprow(dtl.Rows.Count) As DataRow
Dim curid As Integer, previd As Integer
curid = dtl.Rows(0)(0)
previd = dtl.Rows(0)(0)
For i = 0 To dtl.Rows.Count - 1
tmprow(i) = xWdtTran.NewRow()
tmprow(i).Item("cmpid") = dtl.Rows(i)(0)
tmprow(i).Item("cmpname") = dtl.Rows(i)(1)
tmprow(i).Item("idcmp") = dtl.Rows(i)(0)
xWdtTran.Rows.Add(tmprow(i))
If curid = previd Then
Dim tmprow1(totDay) As DataRow
Dim stkDt As Date = CDate(Me.TextBox1.Text)
For j = 0 To totDay
tmprow1(j) = xWdtTran.NewRow()

tmprow1(j).Item("cmpid") = ""

If j = 0 Then
tmprow1(j).Item("cmpname") = Format(CDate(Me.TextBox1.Text), "dd-MM-yyyy")
tmprow1(j).Item("idcmp") = dtl.Rows(i)(0)
Else
stkDt = stkDt.AddDays(1)
tmprow1(j).Item("cmpname") = Format(stkDt, "dd-MM-yyyy")
tmprow1(j).Item("idcmp") = dtl.Rows(i)(0)
End If
xWdtTran.Rows.Add(tmprow1(j))
Next

Else

End If
Next

If Not xWdtTran Is Nothing Then
If xWdtTran.Rows.Count > 0 Then
Me.DataGrid1.DataSource = xWdtTran
Me.DataGrid1.DataBind()
End If
End If
End Sub

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then

If e.Item.Cells(0).Text <> " " Then
CType(e.Item.Cells(2).Controls(1), TextBox).Style("display") = "none"
End If
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
Dim cmdIns As SqlCommand, strSQl As String

For i = 0 To Me.DataGrid1.Items.Count - 1
If Me.DataGrid1.Items(i).Cells(0).Text = " " Then
conn.Open()
strSQl = "INSERT INTO StockDetails (fk_cmpid,stkDt,Amount) VALUES(" & Me.DataGrid1.Items(i).Cells(3).Text & ",'" & CDate(Me.DataGrid1.Items(i).Cells(1).Text) & "'," & CType(Me.DataGrid1.Items(i).Cells(2).Controls(1), TextBox).Text & ")"
cmdIns = New SqlCommand(strSQl, conn)
cmdIns.CommandType = CommandType.Text
cmdIns.ExecuteNonQuery()
conn.Close()
End If
Next

Me.DataGrid1.DataSource = Nothing
Me.DataGrid1.DataBind()
End Sub

 

This Question is not yet answered!

 
 

Related Answered Questions

 

Related Open Questions