0

I have a radiobuttonlist in a gridview in EditItemTemplate. When i click update in a Row the RBL is correctly displayed with his selected value 1 . But if i click the next ROW, like the AlternatingRowStyle, the RBL is displayed but without his selected value 2

The html:

<asp:GridView ID="GVDER" runat="server" AutoGenerateColumns="False" ShowHeaderWhenEmpty="True" DataKeyNames="DERINS,DERANA"
    OnRowCommand="GVDER_RowCommand"
    OnRowEditing="GVDER_RowEditing"
    OnRowUpdating="GVDER_RowUpdating"
    OnRowCancelingEdit="GVDER_RowCancelingEdit"
    OnRowDeleting="GVDER_RowDeleting"
    OnRowDataBound="GDVER_RowDataBound"
    AllowSorting="True" 
    CellPadding="4" 
    ForeColor="#333333" 
    GridLines="None" 
    AllowPaging="true"  
    PageSize="8">

<asp:TemplateField  >
    <HeaderTemplate>
         <asp:Label ID="lblHIVA"  style="text-align:center" runat="server" Text="IVA"  ></asp:Label>
     </HeaderTemplate>
    <ItemTemplate>
        <asp:Label ID="lblIva" runat="server" Text='<%# Eval("DERIVA") %>' width="50px" ></asp:Label>
    </ItemTemplate>
    <EditItemTemplate> 
        <asp:RadioButtonList ID="RBLIva" runat="server" RepeatDirection="Horizontal" width="250px">
            <asp:ListItem style="margin-right:20px;text-indent:5px" Value="0.0"> 0% </asp:ListItem>
            <asp:ListItem style="margin-right:20px;text-indent:5px" Value="10.5"> 10,5% </asp:ListItem>
            <asp:ListItem style="margin-right:20px;text-indent:5px" Value="21.0" > 21% </asp:ListItem>
        </asp:RadioButtonList>
    </EditItemTemplate>
    <ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>

In the CodeBehind:

public partial class derivacion_listado_actualizable : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Request.IsAuthenticated)
        {
            Response.Redirect("~/Account/Login.aspx");
        }

        
        if (!IsPostBack)
        {
            CargarGridView();
        }
    }
    protected void CargarGridView()
    {
        
        
        DataTable dtbl = new DataTable();
        SqlDataAdapter dataAdapter = null;

        SqlConnection edo = new SqlConnection();
        edo.ConnectionString = ConfigurationManager.ConnectionStrings["JuncalCon"].ConnectionString;

        try
        {
            edo.Open();
            using (SqlCommand com = edo.CreateCommand())
            {
                com.CommandText = "Select * FROM DERAUX Where DERVAL ='N' ";

                dataAdapter = new SqlDataAdapter(com.CommandText, edo);

                dataAdapter.Fill(dtbl);

                if(dtbl.Rows.Count >0)
                {
                    GVDER.DataSource = dtbl;
                    GVDER.DataBind();
                }
               
            }
            
        }
        catch /*...*/
    }
    protected void GDVER_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowState == DataControlRowState.Edit)
            {
                decimal IvaValue = (decimal)DataBinder.Eval(e.Row.DataItem, "DERIVA");
                RadioButtonList rb = (RadioButtonList)e.Row.FindControl("RBLIva");
                rb.Items.FindByValue(IvaValue.ToString(CultureInfo.CreateSpecificCulture("en-US"))).Selected = true;
            }
        }
    }
    protected void GVDER_RowEditing(object sender, GridViewEditEventArgs e)
    {
        lblSuccess.Text = "";
        GVDER.EditIndex = e.NewEditIndex;
        CargarGridView();
    }

What im doing wrong..? thx in advance.

Grigory Zhadko
  • 1,484
  • 1
  • 19
  • 33
gabriel
  • 1
  • 1

1 Answers1

0

The solution is in this post

How to check for combined RowState 'Altering | Edit' in RowDataBound?

The e.Row.RowState can take

  • Alternate
  • Edit
  • Insert
  • Normal
  • Selected

Also Alternate con combine with other states.

gabriel
  • 1
  • 1