Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
protected void update_Status_Click(object sender, EventArgs e)
    {
        
        List<int> id = new List<int>();
       
        foreach (GridViewRow row in GridView1.Rows) 
        {
            int i = row.RowIndex;
        
            CheckBox cb = (CheckBox)row.FindControl("SelectCashout");
 
            if (cb != null && cb.Checked) 
            {
                

                if (GridView1.Rows[i].Cells[2].Text == "Requested")
                {
                    int x = Convert.ToInt32(GridView1.Rows[i].Cells[0].Text);
                    id.Add(x);
                }
            } 
        } 
    }


When I debug it I am getting "GridView1.Rows[i].Cells[2].Text" value as empty string.
This is not a Gridview event, it is button event out side the gridview.
I tried row.Cells[2].Text it doesn't help...

What am I missing here? any help thanks
Posted
Updated 21-Dec-10 18:24pm
v5

Hi Andy,
Thanks for your reply. It's not Edit/Update button on Gridview.
I am giving option to the user to select which rows he wants to update.
Based on his selection through checkbox I have to update just one cell value in the gridview and collect primary key of that row in the table so I will update datasource at backend(That code I havn't included)

Hope you understood. updating one cell value is not mandatory because I am updating datasource and I can rebind it. Collecting that row's Primary key(Datasource Table's) is

"GridView1.Rows[i].Cells[0].Text" important to update database.


Thanks
 
Share this answer
 
Comments
Toniyo Jackson 22-Dec-10 1:46am    
Don't write your comments here. You have add comment button below all answers. so write your comments below the appropriate answer
Hi Jayadheer,

I think you use CommandField in GridView and click on this CommandField to edit GridRow, right???

If you did that, please re-bind datasource for the GridView, because when the template control in the column turns to edit mode, the default text is empty. So you must re-bind the GridView

Hope it helps you.

Andy
 
Share this answer
 
In my code, GridView1.Rows[i].Cells[2].Text is OK, has value. Please see the column 2nd on the Grid, does it have value?
 
Share this answer
 
Hi,

LOOK ON YOUR GRIDVIEW, it has VALUE or NOT? If it does not have VALUE, maybe you didn't bind data for this field or you missed DataField property.

Andy
 
Share this answer
 
v2
int x = GridView1.Rows[i].Field<int32>("Your Column or Field Name");</int32>
 
Share this answer
 
v4
Comments
wizardzz 22-Dec-10 11:17am    
I can't get the closing int32 tag to go away, it should not be there in the actual code. I keep trying to remove it, but it shows up when I try to update. Please don't down-rate the answer based on this error with CP's posting logic.
Jayadheer Reddy 22-Dec-10 20:49pm    
Thanks for your relay.
Gridview1.Rows[i] does not have Field property... Error..
I have all columns with template fields
wizardzz 23-Dec-10 11:11am    
Oh, sorry, I forgot I was using a 3rd party gridview. I'll get back to you.

Just so I understand the question correctly. The Value of the cell is empty, is this expected? Do you want to set your int value to 0 if it is empty?

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