Solved

reference gridview dataitem in rowediting event

Posted on 2008-06-18
6
2,721 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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