Enviar matriz de valores de casilla de verificación de tabla a través de HTTP Post

I have this table with which I create dynamic checkboxes (the number of records may/will vary) the idea is that I can select a checkbox on whatever table row and "Send" those records.

I want to send an array of ID's off to a different page for processing - but i'm very stuck!

Here is my table/form code

<form action="processingpage.aspx" method="post">
  <asp:Repeater ID="GroupList" runat="server">
       <table id="grouptable" class="table"> 
              <th>Last Modified</th>
            <input type="checkbox" name="BroadcastSelect[]" value="<%# Eval("Group_ID") %>"</input></td>
          <td><%# Eval("Group_ID") %></td>
          <td><%# Eval("DESC") %></td>
          <td><label id="test">hello</label></td>
          <td><a class="btn btn-info" href="<%# Eval("gURL") %>">Edit</a>/td>
  <input class="btn primary" type="submit" value="Broadcast"/>

I think this is sending the array ok as I managed to see this via Request.in

BroadcastSelect[]TESTGROUP (which is one of the items I sent)

but on my receiving page I'm getting nothing but blank text I've tried

Label1.Text = Page.Request.Form["BroadcastSelect[0]"];


Label1.Text = Page.Request.QueryString["BroadcastSelect[0]"];

but no values are printed. Can anyone point me in the right direction?

preguntado el 31 de julio de 12 a las 10:07

Su <input> is not correctly formatted, it is not being closed off correctly. Don't know if that will make any difference though -

just spotted this myself, no difference though :( -

1 Respuestas

I think the problem is that it is not possible to index the <input name="BroadcastSelect[]"> a través de una Request.Form or Request.QueryString.

If you breakpoint in the code, you will see that the Request.Form object will have Request.Form["BroadcastSelect[]"] as one of the available items, which will return a CSV list of values.

So try using this instead...

string broadcastSelect = Request.Form["BroadcastSelect[]"];
if (broadcastSelect != null)
   string[] broadcastSelectParts = broadcastSelect.Split(',');
   Label1.Text = broadcastSelectParts[0];

Obviously the code in the block can also be brought down to a single line, but if you want something other than the 1st item, check that you're not selected an "out of bound" index...

Label1.Text = broadcastSelect.Split(',')[0];

Respondido 31 Jul 12, 11:07

that seems to be coming through :) is there any way to determine how many items are in the post? thanks for the help by the way! - JazziJeff

broadcastSelectParts.Length? Obviously that would only work if there is a valid string to split, as an empty string split will produce one item. EDITAR however, saying that, there is the StringSplitOptions.RemoveEmptyEntries option that you can use on Split - Freefaller

@JazziJeff, or are you talking about the total number of posts in the entire Request.Form? That is more tricky, as you have to take into account the _EVENTTARGET type items, as well as the indexed items such as your input above - Freefaller

no i was talking about that specific element of the post - its been a long day , i forgot about .Length :) thats enough to get me going though thanks again for the help! - JazziJeff

You're welcome @JazziJeff - good luck with the rest of your project, and I hope (for your sake) that your day end soon :-) - Freefaller

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.