?
Solved

Add a textbox and other controls to a gridview

Posted on 2008-06-18
3
Medium Priority
?
822 Views
Last Modified: 2013-11-07
All,

I am looking at adding a basket to a web page.  I have this working to a basic standard, but now want to add extra functionality to it.

At the moment I have the data held in a session array that i populate on the basket screen in a grid view.

I have populated the gridview with 6 columns .  The first 2 are not data assigned by the session variables but is a check box column called remove and a text box column called Tyres required that has a text box in.

The other columns are assigned by code (see snippet)

Basically I have three problems that i do not know how to do.

1.  Because I used the designer to add the first 2 columns and code the rest the designer columns appear first in the gridview when i would like them to appear at different stages.  How do I write the code to add a column and in that column have a text box and how do i do the same but for a check box?

2.  How do I then reference that columns text box or check box?  At the moment I loop through each row  and use this

Dim tb As TextBox = CType(r.FindControl("TextBox1"), TextBox)

Would this be different?

3.  On a different note i would possibly like to make something on the row happen if the check box is ticked.  Is there an event that says when a row is changed do something.  What would the code be say on the check box being checked i wanted the textbox column for this row only to be disabled, but still in the view?

Thanks for your help.
If Not IsPostBack Then
 
 
            Dim arr As String(,) = cartItems
 
            'Label1.Text = cartItemCount
 
            Dim t As New DataTable("salesOrder")
            t.Columns.Add("Part_Number")
            t.Columns.Add("Tyre_Size")
            t.Columns.Add("Aircraft")
            t.Columns.Add("Main_or_AUX")
 
            ' Loops around - 1 because it is a count not an array position
            For i As Integer = 0 To cartItemCount - 1
                t.Rows.Add(arr(i, 0), arr(i, 1), arr(i, 2), arr(i, 3))
            Next
 
            GridView1.DataSource = t
            GridView1.DataBind()
 
        End If

Open in new window

0
Comment
Question by:yo_daz_uk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:yo_daz_uk
ID: 21817786
Any ideas?
0
 
LVL 12

Accepted Solution

by:
renjurdevan earned 930 total points
ID: 21819283
0
 

Author Closing Comment

by:yo_daz_uk
ID: 31468401
the answer did not really answer my question, but got me thinking a different way.  Basically you add your data bound fields in the grid designer, but you set there data field attributes in the columns collection to the name of the column you have created in code.

Also, I unticked auto generate fileds in the columns collection I think this helped.  Obviously this was only section 1 out of 3 the answer for but no one else is writing any comments.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question