Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using grid view that shows all the tasks for log in user. User can check/unchecked tasks and based on check box status, record is updated on grid view.
My grid view has template field which has header template and item template. Header template contains check boxes and asp:button and item template contains check boxes. On check/unchecked of header template check boxes, all check boxes in item template are checked/unchecked. The purpose of asp:button is to update records on database based on check/unchecked status of rows.

What i wanted is on click of asp:button on header template, all records of grid view are to be fetched including check boxes checked status so that the check status can be updated on database.

I had used row command event of grid view. It fired on handler on click of button. However, I am not able to get records.
Which event is used to accomplish this? How can i do this.

http://stackoverflow.com/questions/28870200/how-to-get-records-of-grid-view-on-click-of-button-on-header-of-gridview[^]
Posted
Updated 4-Mar-15 17:55pm
v2

Inside RowCommand you can easily get that particular Row. As you are saying that you want all the rows to be fetched, then inside that event you just need to loop through all the GridViewRow.

Inside the loop, you can get all the details of the rows including the checkbox check status.
 
Share this answer
 
thanks Tadit, I did like this:

C#
protected void gridTransaction_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "headerClicked")
            {
                foreach (GridViewRow row in gridTransaction.Rows)
                {
                    var record = row;
                }
            }
        }


I did some debugging, in record, dataItem shown is null. Also text is blank. I am binding grid on page load..Did i missed something that resulted to null item being binded???
 
Share this answer
 
v3
Comments
Good. Please accept my answer and up vote. :)

Also adding a solution can't notify me. Always add comment to my answer, so that I can know that you have a question.

So, how exactly your binding? Have you checked for IsPostBack or not?
Codes DeCodes 5-Mar-15 11:23am    
yes, i did...the code on page load is
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindGrid();
}
}

private void BindGrid()
{
Transaction transaction = new Transaction();
gridTransaction.DataSourceID = string.Empty;
gridTransaction.DataSource = transaction.GetAllTransactionEntrySaved();
gridTransaction.DataBind();
}
Still, on rowcommand, null value is being shown..
I used jquery to get all elements of gridview in list, then i went to serverside and did operation of saving.
 
Share this answer
 

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