Click here to Skip to main content
15,885,715 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. At the moment gridview showing 10 rows with all the data in all the columns.

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 haven'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.



What am I missing here? any help thanks
Posted
Updated 21-Dec-10 21:09pm
v4
Comments
JF2015 22-Dec-10 3:10am    
Fixed the code formatting.

1 solution

Below code may help you
C#
LinkButton lbtnID= (LinkButton)sender;
int index = ((GridViewRow)lbtnID.NamingContainer).RowIndex;

Label lblID= ((Label)gdDiscount.Rows[index].Cells[1].FindControl("lblID"));
int  value= Convert.ToInt32(lblID.Text.ToString());

Write this inside link button in gridview.. Hope this will give you some idea..Let me know if you have still problem
 
Share this answer
 
v2
Comments
thatraja 22-Dec-10 13:53pm    
code block added
Jayadheer Reddy 22-Dec-10 21:46pm    
You are amazing.
Label lblID= ((Label)gdDiscount.Rows[index].Cells[1].FindControl("lblID"));

This is what exactly I want. Thanks a ton dude.

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