Solved

reference gridview dataitem in rowediting event

Posted on 2008-06-18
6
2,697 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now