Solved

reference gridview dataitem in rowediting event

Posted on 2008-06-18
6
2,711 Views
Last Modified: 2013-11-07
Ok I have a gridview bound to a sql datasource, on of the fields it returns is a pipe delimited string.
I use a template control with a label in the item template that sends the string to a function that splits it and displays a ul.

now in the edit item template i have a checkbox list. When the user clicks the edit button, I want to reference the control and the dataitem, loop through it and select certain checkboxes.

I can reference the checkbox list fine, but how can i get the dataitem?
Or is there a better way to do this?
0
Comment
Question by:Dustin Hopkins
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:prairiedog
ID: 21822089
>>>I want to reference the control and the dataitem,
Which control do you want to reference? The label?
0
 
LVL 14

Author Comment

by:Dustin Hopkins
ID: 21826454
No i want to reference the checkboxlist, did that with no problem.

Its the dataitem thats giving me the problem, i tried using the eval.databinder method like you would use in the onrowdatabound event, but its throwing object reference not set to an instance of the object.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21826527
Can you post the code that you reference the checkboxlist and the code you use to get the dataitem?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 0 total points
ID: 21828328
Ok, I got it working, I just had to add this to my datarowbound event
If e.Row.RowState = DataControlRowState.Edit Or _
 (e.Row.RowState = (DataControlRowState.Alternate Or DataControlRowState.Edit)) Then
 
            Dim cbl As CheckBoxList = CType(e.Row.FindControl("cblComp"), CheckBoxList)
            If DataBinder.Eval(e.Row.DataItem, "reqComp").ToString() <> "" Then
                Dim traincomp() As String = DataBinder.Eval(e.Row.DataItem, "ReqComp").ToString.Split("|")
                For Each s As String In traincomp
                    cbl.Items.FindByValue(s).Selected = True
                Next
            End If
        End If

Open in new window

0
 
LVL 10

Expert Comment

by:Smart_Man
ID: 22590835
do you mean to access the gridview.rowediting event ?

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowediting.aspx

waiting for your reply
0
 
LVL 14

Author Comment

by:Dustin Hopkins
ID: 22592269
No, I was having problems referencing the dataitem associtated with a row during the rowediting event. I didn't realize that that was done in the rowdatabound event. As the row rebinds when switching to an editing view. Basically i was storing a string of data in a single db column, seperated by pipes. Such as "one|two|three". Then I took this and broke it down and used it to fill a checkboxlist. Thanks though.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question