Welcome Guest Search | Active Topics | Sign In | Register

Grid Problem EditorTemplate.FindControl to find Dropdownlist.selectedValue Options
Jennifer
Posted: Wednesday, March 26, 2008 12:37:18 AM
Rank: Newbie
Groups: Member

Joined: 1/8/2008
Posts: 3
Hello,

I'm using your Grid and I am trying to get the selectedvalue of a dropdownlist within the grid.
I'm trying to use the following code that is not finding the EditorTemplate.FindControl method. I've confirmed I'm using your latest Dll build 5.0.44.2 How do I get the selectedValue of a DDL ?


Code behind

Dim CustCol As EO.Web.CustomColumn = DirectCast(Grid1.Columns(7), EO.Web.CustomColumn)

Select Case CustCol.EditorTemplate.FindControl("ddlPaymentType")

Case "Cashiers Check"
objPayment.PaymentTypeID = 1
Case "Personal Check"
objPayment.PaymentTypeID = 2
Case "Cash"
objPayment.PaymentTypeID = 3
Case "Credit Card"
objPayment.PaymentTypeID = 4
Case "Paypal"
objPayment.PaymentTypeID = 6
Case "Wire Transfer"
objPayment.PaymentTypeID = 7
End Select



ASPX CODE:

<eo:CustomColumn datafield="PaymentTypeID"
ClientSideBeginEdit="on_begin_edit"
ClientSideEndEdit ="on_end_edit">
<EditorTemplate >


<select datatextfield="PaymentTypeName" id="DDLPaymentType" >
<option>--Please Select-- </option>
<option>Cashiers check</option>
<option>Paypal</option>
<option>Personal Check</option>
<option>Credit Card</option>
<option>Cash</option>
<option>Wire Transfer</option>

</select>

</EditorTemplate>
</eo:CustomColumn>


Java Script


function on_begin_edit(cell)
{
//Get the current cell value
var v = cell.getValue();

//Use index 0 if there is no value
if (v == null)
v = 0;

//Load the value into our drop down box
var dropDownBox = document.getElementById("DDLPaymentType");
dropDownBox.selectedIndex = v;
}

function on_end_edit(cell)
{
//Get the new value from the drop down box
var dropDownBox = document.getElementById("DDLPaymentType");
var v = dropDownBox.selectedIndex;
var PaymentTypeID = dropDownBox.selectedIndex;

//Use null value if user has not selected a
//value or selected "-Please Select-"
if (v == 0)
v = null;

//Return the new value to the grid
return v;
}</SCRIPT>

eo_support
Posted: Wednesday, March 26, 2008 7:34:25 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,098
Hi,

You won't be able to do that. The reason is our Grid allows you to update multiple cells before submitting back to the server. So by the time you are back to the server, multiple cells might have been changed. If we were to allow you get value from EditorTemplate, you would only be able to get one value. Obviously that won't work.

You must get the modified value from the cell. To do that, you will first get a list of modified items (rows) through ChangedItems property, from there you can get a list cells and check whether the cells are modified and get the new value.

Thanks
Jennifer
Posted: Wednesday, March 26, 2008 9:38:13 AM
Rank: Newbie
Groups: Member

Joined: 1/8/2008
Posts: 3
I understand that I need to check the changeditem property. I'm doing that in the code below. I'm having problems trying to find the correct syntax to access the selectedvalue from a dropdownlist within the grid. Do you have an example of that ?

For Each item In Grid1.ChangedItems

Dim objPayment As New Payments(item.Key)
objPayment.ReservationID = Session("SesReservationID")
objPayment.PaymentAmt = item.Cells("PaymentAmt").Value
objPayment.PaymentDate = item.Cells("PaymentDate").Value
objPayment.PaymentDesc = item.Cells("PaymentDesc").Value
objPayment.PaymentRefNo = item.Cells("PaymentRefNo").Value
objPayment.PaymentTypeID = item.Cells("PaymentTypeID").Value

BELOW IS NOT WORKING

'Dim CustCol As EO.Web.CustomColumn = DirectCast(Grid1.Columns(7), EO.Web.CustomColumn)
' Select Case CustCol.ClientSideEndEdit.EditorTemplate.FindControl("ddlPaymentType")
Select Case item.Cells("ddlpaymentType").Value
Case "Cashiers Check"
eo_support
Posted: Wednesday, March 26, 2008 10:00:31 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,098
Jennifer wrote:
For Each item In Grid1.ChangedItems

Dim objPayment As New Payments(item.Key)
objPayment.ReservationID = Session("SesReservationID")
objPayment.PaymentAmt = item.Cells("PaymentAmt").Value
objPayment.PaymentDate = item.Cells("PaymentDate").Value
objPayment.PaymentDesc = item.Cells("PaymentDesc").Value
objPayment.PaymentRefNo = item.Cells("PaymentRefNo").Value
objPayment.PaymentTypeID = item.Cells("PaymentTypeID").Value


This above code is correct.

Jennifer wrote:

'Dim CustCol As EO.Web.CustomColumn = DirectCast(Grid1.Columns(7), EO.Web.CustomColumn)
' Select Case CustCol.ClientSideEndEdit.EditorTemplate.FindControl("ddlPaymentType")
Select Case item.Cells("ddlpaymentType").Value
Case "Cashiers Check"


This code is wrong. Everything should come from Cell.Value property. The way a CustomColumn works is:

1. When you edit the cell on the client side, your on_end_edit is called. This is when you fetch the value of your custom item and transfer it to Cell.Value;
2. You would then rely on Cell.Value alone on the server side;

We have samples demonstrated both step 1 and step 2 but unfortunately we don't seem to have one that demonstrates both as a single sample. But it is exactly the same on the server side for a CustomColumn. The difference is on the client side.

Thanks
Jennifer
Posted: Saturday, March 29, 2008 10:00:29 AM
Rank: Newbie
Groups: Member

Joined: 1/8/2008
Posts: 3
Again, all I am trying to do is determine what the user selected from the DDL within the GRID
and then save it to a Database by looping through the Grid1.ChangedItems

PLEASE HELP, I've wasted too much time already.

I understand that the code I provided is not correct. I've tried to follow your examples, but do not know what you mean by "rely on Cell.value on the server side". I need specific examples ?
QUESTIONS:
1) What is the Specific syntax for Javascript on_end_edit function to fetch the value of your custom item and to "transfer it to Cell.Value "???; What is the specific syntax to "transfer it to a Cell.value" .

2) HOW DO I reference the Custom column cell value (i.e. what was selected) OF A DROPDOWNLIST WITHIN A GRID ON THE SERVER SIDE in the code-behind?

if the only thing I change is the selected value of the dropdownlist on the grid and then loop through it with the following code -- It detects the the dropdownlist Cell was modifed, but the cell.value is null.
For Each item In Grid1.ChangedItems

Dim objPayment As New Payments(item.Key)
objPayment.ReservationID = Session("SesReservationID")
objPayment.PaymentAmt = item.Cells("PaymentAmt").Value
objPayment.PaymentDate = item.Cells("PaymentDate").Value
objPayment.PaymentDesc = item.Cells("PaymentDesc").Value
objPayment.PaymentRefNo = item.Cells("PaymentRefNo").Value
' objPayment.PaymentRefNo = item.Cells("PaymentTypeid").Value

Dim cell As GridCell
For Each cell In item.Cells
If cell.Modified Then
Dim ttt As String = String.Format("Cell Changed: Key = {0}, Field = {1}, New Value = {2}", item.Key, cell.Column.DataField, cell.Value)

s += "<br />"
s += ttt
End If
Next cell


eo_support
Posted: Saturday, March 29, 2008 12:28:48 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,098
Jennifer wrote:
1) What is the Specific syntax for Javascript on_end_edit function to fetch the value of your custom item and to "transfer it to Cell.Value "???; What is the specific syntax to "transfer it to a Cell.value" .


Transfer it to Cell.Value = Transfer drop down list selection (for example, the index) to Cell.Value = return drop down list selection from your on_end_edit.

So the on_end_edit function posted in your original post (seems to be based on our sample code) is where this happens. It gets the value from your drop down list and return it. The Grid calls this function and stores the return value into Cell.Value;


Jennifer wrote:
2) HOW DO I reference the Custom column cell value (i.e. what was selected) OF A DROPDOWNLIST WITHIN A GRID ON THE SERVER SIDE in the code-behind?


You should absolutely forget about that you have a drop down list when you are working on the server side. On the server side there are GridItem, GridCell and GridCell.Value. That's all you have. If your GridCell.Value does not have the correct value, then something on your client side, most likely your client side on_end_edit is wrong. In your case, since the EditorTemplate is a "select" element, not an asp:DropDownList, so there is never a DropDownList on the server side;


Jennifer wrote:
if the only thing I change is the selected value of the dropdownlist on the grid and then loop through it with the following code -- It detects the the dropdownlist Cell was modifed, but the cell.value is null.


Check your version. I believe in our early versions, the Grid does not submit a cell change unless you have left the cell. So if you just change it without moving the focus cell to another cell, the change will be discarded.

If that looks fine, then try to compare our sample code and your code because our sample code works fine. If you can not find the problem we can set up a web meeting to take a look. Just let us know.

Hope this helps.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.