Sign in to follow this  
quintelab

Gridview

Recommended Posts

Estou usando uma GridView com várias TemplateField, na coluna Template estou usando um checkbox.

Estou tentando através de uma condição trazer o checkbox marcado ou não.

O que eu fiz:

No evento RowDataBound

While dr.Read
            If dr.Item("AREATU_RESPOSTA") = "S" Then
                CType(gvAtuacao.Rows(e.Row.RowIndex).FindControl("ChAtende"), CheckBox).Checked = True
            Else
                CType(gvAtuacao.Rows(e.Row.RowIndex).FindControl("ChAtende"), CheckBox).Checked = False
            End If
        End While

Da o seguinte erro:

Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index

Linha:

CType(gvAtuacao.Rows(e.Row.RowIndex).FindControl("ChAtende"), CheckBox).Checked = True

Share this post


Link to post
Share on other sites

Solução:

Alimentei um ArrayList para minha condição

Depois no evento RowDataBound:

If e.Row.RowType = DataControlRowType.DataRow Or e.Row.RowType = DataControlRowType.EmptyDataRow Then
            Dim ck As CheckBox = CType(e.Row.FindControl("ChAtende"), CheckBox)
            If Not IsNothing(ck) Then
                If vPesJurAtende(e.Row.RowIndex).ToString = "S" Then
                    ck.Checked = True
                Else
                    ck.Checked = False
                End If
            End If
        End If

Falows

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this