How to get id value when try to loop within repeater control?

Ahmed Salah Abed Elaziz 390 Reputation points
2023-02-24T18:56:46.0133333+00:00

I working on asp.net web forms. I can't get value of id inside repeater control.

i need to get id when loop within repeater control

string Id = gvr.Items[5].ToString();

what I do within code is :

1- click on print button to update status column on database based on id if checkbox checked

2- then after that will loop within repeater control to get checkbox value have checked true

3-get id from repeater and update on database column status with true when checkbox checked is true .

what I try as below :

protected void Print_Click(object sender, EventArgs e)
    {
        int counter = 0;
        foreach (RepeaterItem gvr in repPSStatus.Items)
        {

            if (((System.Web.UI.WebControls.CheckBox)gvr.FindControl("chkSel")).Checked == true)
            {
                string Id = gvr.Items[5].ToString();// here is issue 
  
                string msg = busiObj.updatestatus(Id);
                if (msg == "SUCCESS")
                {
                    counter = counter + 1;
                }

            }
        }

    }
and on reprint.aspx page

 
    <thead>
    
    
    
    
    </thead>
    <tbody>
    <asp:Repeater runat="server" ID="repPSStatus">
    <ItemTemplate>
    
    
    
    
    </ItemTemplate>
    </asp:Repeater>
    </tbody>
    
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,235 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,168 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Ahmed Salah Abed Elaziz 390 Reputation points
    2023-02-24T22:58:59.5533333+00:00

    what i need actually get value of id that have checkbox checked

    i need to modify this line to get id value from repeater

    string Id = gvr.Items[id].ToString();// here is issue


  2. Jose Zero 576 Reputation points
    2023-02-25T12:53:38.02+00:00

    Your code do not show what is inside Repeater, we have no idea what is inside, it can have just a control or a bunch of nested controls.
    Best I can suggest (following AgaveJoe), is use FindControl as you made to get Checkbox.Checked.
    Use grv.Items[5].FindControl(<place control ID here>)

    0 comments No comments