| |

VerySource

 Forgot password?
 Register
Search
View: 725|Reply: 6

Unable to get the value in the TextBox in the GridView template column, which expert helps to see.

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-3 18:30:01
| Show all posts |Read mode
The second column of the GridView is the template column, there is a TextBox, and the first column is the bound column. I use the following code to iterate through the values ​​in the TextBox but the values ​​are always empty.
 int iNum = GridView1.Rows.Count;
        for (int i = 0; i <iNum; i ++)
        {
            GridViewRow selectedRow = GridView1.Rows [i];
            TableCell contactName = selectedRow.Cells [0];
             TableCell tempCell = selectedRow.Cells [1];
     
                TextBox textBox1 = (TextBox) tempCell.FindControl ("TextBox1");
                strNum = textBox1.Text;
                strTitle = contactName.Text;
                hash.Add (strTitle, strNum);
            }
        
        }

Is it possible to mix template columns and binding columns?
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-3 20:33:01
| Show all posts
No problem.
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-3 21:42:01
| Show all posts
Yeah, I'm also baffled.
Reply

Use magic Report

0

Threads

64

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-1-3 23:33:01
| Show all posts
Explain when it should have value.
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-4 00:00:01
| Show all posts
Where is this code written? Is there any data binding at this time?
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-6 10:57:01
| Show all posts
Written in the Click event of another Button on the page, tried it for a long time, and finally solved it, thank you:
The code is changed to the following:
String strTitle, strNum;
        Hashtable hash = new Hashtable (50);
         int iNum = GridView1.Rows.Count;
        for (int i = 0; i <iNum; i ++)
        {

            CheckBox check = (CheckBox) GridView1.Rows [i] .Cells [0] .Controls [1];

            if (check.Checked)
            {
     
            TextBox textQuantity = (TextBox) GridView1.Rows [i] .Cells [2] .Controls [1];
                strTitle = GridView1.Rows [i] .Cells [1] .Text;

                strNum = textQuantity.Text;
                 hash.Add (strTitle, strNum);
             }
        
        }
       Session ["basket"] = hash;
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-26 16:45:01
| Show all posts
Why I used the above method, but still can't get the modified value in the bound TextBox?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list