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

Hi experts,

I am trying to create a dynamic columns in gridview, number of columns are decided at run time as per the datatable. Datatable's first 3 columns and last 2 columns are fixed, in between gets generated at run time. I have generated textboxes at runtime for enrty for the autogenerated columns in gridview.I have done with this, but when i try to access the textboxes in order to update my datatable, i'm getting empty string(""),


http://www.universalthread.com/Thread%20photos/2012/01539804.gif[^]
Posted
Updated 31-Mar-12 1:52am
v2
Comments
Mohamed Mitwalli 31-Mar-12 10:30am    
Hi , can you supply ur code
Pandey Vijay Kumar S. 3-Apr-12 1:24am    
The textboxes generated at run time by the way,
>
>
> Public Sub GrdAPTB_RowCreated(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GrdAPTB.RowCreated
> Try
>
> If (e.Row.RowType = DataControlRowType.DataRow) Then
> Dim dt As DataTable = Session("DTItemAPTB")
>
> Dim grd As GridView = CType(sender, GridView)
> For j As Integer = 4 To dt.Columns.Count - 1
> Dim txt As TextBox = New TextBox
> txt.ID = "txtedit" & j.ToString()
> txt.Enabled = True
> e.Row.Cells(j).Controls.Add(txt)
> Next
> End If
> Catch ex As Exception
> End Try
> End Sub
>
> *****************
>
> Protected Sub GrdAPTB_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GrdAPTB.RowDataBound
> Try
>
> Dim dt As DataTable = Session("DTItemAPTB")
> If (e.Row.RowType = DataControlRowType.DataRow) Then
> If z < dt.Rows.Count Then
> For i As Integer = 4 To dt.Columns.Count - 1
> Dim txtdb As TextBox = New TextBox
> txtdb.ID = "txtdb" + i.ToString()
> txtdb.Enabled = True
> txtdb.Text = dt.Rows(z)(i - 1).ToString()
> e.Row.Cells(i).Controls.Add(txtdb)
> If i = dt.Columns.Count - 1 Then
> txtdb.Attributes.Add("onkeypress", "return validateinput(event)")
> End If
> Next
> z += 1
> End If
>
> End If
>
> Catch ex As Exception
> alt.Show(ex.Message)
> End Try
> End Sub
>
>
> **************And i'm trying to access the textbox values here
>
> Protected Sub btnSort_Click(sender As Object, e As System.EventArgs) Handles btnSort.Click
> Try
> Dim dt As DataTable = Session("DTItemAPTB")
>
> Dim dr As DataRow
> For Each gvr As GridViewRow In GrdAPTB.Rows
> dr = dt.Rows(gvr.RowIndex)
> For f As Integer = 4 To dt.Columns.Count - 2
> If f < dt.Columns.Count - 2 Then
>
> dr(f) = CType(gvr.FindControl("txtedit" + f.ToString()), TextBox).Text
> dt.AcceptChanges()
> Else
> dr(f) = Val(CType(gvr.FindControl("txtedit" + f.ToString()), TextBox).Text)
> dt.AcceptChanges()
> End If
> Next
> Next
> End try
>
> *********
> the value of
> CType(gvr.FindControl("txtedit" + f.ToString()), TextBox).Text
> is showing " "
>
>
> *****************
>

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