开发者

Accessing checkbox inside a html table loop, from code behind (.NET)

Hey guys, I have a question about asp.net

I have this table with checkbox for each row:

http://i.stack.imgur.com/9QBLf.png

table code inside the 开发者_JS百科ASPX page:

http://i.stack.imgur.com/dLbP1.png

So I'm trying to implement the delete selected button.. How exactly do i point to the specific checkbox for a particular row from codebehind when all 3 have the same name chkSelected? I know how to do it with a gridview, but not quite sure how if we do it with a for loop..

Can I do something like this inside btnDelete_Click?

    foreach (Control control in Controls)
    {
        try
        {
            CheckBox chkCurrent = (CheckBox)control;
            if (chkCurrent.Checked)
            {
                Partners partner = new Partners(chkCurrent.ID); <- reference id here
                partner.Delete();
            }
        }
        catch { }
    }

Thank you in advance!


WebForms ASP.Net is kinda old and busted, but I would suggest just doing it brute-force and forgoing ASP.Net's control layer. Render each checkbox with a unique name thusly:

<input type="checkbox" name="select_press<%= i %>" ...

Then, in your codebehind, inspect the Request collection for the presence of each checkbox.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜