¿RadiobuttonList dentro de las actualizaciones de gridview pero no muestra la actualización?

I've got a gridview (asp.net) with a checkbox and a radiobuttonlist. Above this gridview I have a button that allows the user to set all SELECTED items in the gridview to a particular value. What I mean by selected is that checkbox that is inside the gridview is checked. This gridview is inside an updatepanel and I dont know if this is the reason I am having an issue but here is my issue.

The gridview as I said has a checkbox like so:

 <ItemTemplate>
  <asp:CheckBox ID="chkSelector" runat="server" 
    ToolTip="Select row?" />
 </ItemTemplate>

And a radiobutton list like so:

 <asp:RadioButtonList ToolTip="Please provide an answer to the method." AutoPostBack="true" RepeatDirection="Horizontal" ID="rbAnswer" runat="server" SelectedValue='<%# DataBinder.Eval(Container, "DataItem.AnswerID")%>' OnSelectedIndexChanged="rbAnswer_SelectedIndexChanged">
                                    <asp:ListItem Text="Yes" Value="Yes" style="color:green;"></asp:ListItem>
                                    <asp:ListItem Text="No" Value="No" style="color:red;"></asp:ListItem>
                                    <asp:ListItem Text="N/A" Value="N/A" style="color:gray;"></asp:ListItem>
                                    <asp:ListItem Value="" Text="" style="display: none" />
                                </asp:RadioButtonList>

When you check the checkbox (you can select multiple checkbox (line items in the grid) and then click this button. The button does something to this effect:

foreach (GridViewRow Row in this.gvLineItems.Rows)
                {
                    CheckBox cb = (CheckBox)Row.FindControl("chkSelector");
                    Label id = (Label)Row.FindControl("lblID");
                    if (cb != null && cb.Checked)
                    {
                        long lID = Convert.ToInt32(gvLineItems.DataKeys[Row.RowIndex].Value);
                        RadioButtonList rbl = (RadioButtonList)Row.FindControl("rbAnswer");

                        rbl.Items.FindByText("N/A").Selected = true;
                    }
                }

That is it loops through all items in the gridview. If the item is checked (chkSelector = true) then it sets the radiobutton list answer to "N/A". I debug the code and I can see the answer is set correctly but then when my method is done the User Interface doesnt show the result. Meaning the answer was never set to N/A. It just maintains its original state...

Does anyone know why this is happening? I am using an updatepanel around this so I am not sure if that is the reason ???

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

call the bind Method of gridview after the foreach loop -

@WaqarJanjua - huh??? I am not trying to rebind the gridview... -

radiobuttonlist is inside the gridview and you have made changes to it so I think you have to call the bind method of the grid to show the update. -

@WaqarJanjua - DataBind binds the datasource to the gridview, that has nothing to do with binding a radiobuttonlist selection value to a gridview. That won't work sorry. -

Yes i tried it and it does not work, because that is not what databind is for. You may want to read the documentation on DataBind. -

1 Respuestas

<asp:ListItem Text="N/A" Value="N/A" style="color:gray;"></asp:ListItem>

for (int i = 0; i < gvLineItems.Rows.Count; i++)
{   
 CheckBox cb = (CheckBox)gvLineItems.Row[i].FindControl("chkSelector");   
 RadioButtonList rbl = (RadioButtonList)gvLineItems.Row[i].FindControl("rbAnswer");
 if(cb.checked == true)
{
    rbl.SelectedValue = "N/A";
}
}

Respondido 31 Jul 12, 15:07

Modified it according to your requirement. Hope it helps. - Ruchi

But why wouldnt rbl.Items.FindByText("N/A").Selected=true; ¿trabajo? - oJM86o

Did this code work? if yes you can replace rbl.selectedvalue with your rbl.items.findbytext and test it if it works. Thanks. - Ruchi

Rahi Doshi - That is the issue, it doesnt work with rbl.Items.FindByText, but it works by setting the SelectedValue. I am not sure why... - oJM86o

You can refer to this article, if it could help. foros.asp.net/t/1507149.aspx/1 - Ruchi

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