Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have an editable data grid. When the user clicks the edit button I change a textbox to a dropdown so they can select a new value. I also add a js attribute to the save button so they get prompted for confirmation before commiting the save.

 

This works well for me as I can inform the user of the state they are changing the value FROM before they commit. What I can't figure out is how I can get a handle on what they are changing the value TO before they commit. This is because my js gets bound with the grid, before the user chooses. I could put an auto post back on the ddl but that would be a little cumbersome I think for the user.

If I could just get a handle on the ddl in js I could get the selected value. Trouble is the ddl doesn't maintain the id I give it in html. It gets appended with the .NET ctl_ syntax so I can't use js

 

document.getElementById("ddl");

 

Is there another way to do this?

Wanna-Be C# Superstar
Posted

how about you have your javascript function called with the 'this' as an arugument:

 

'In ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
   Dim dgi as DataGridItem = DirectCast(e.Item, DataGridItem)
   Dim cntl as Control = e.Item.Cells(0).FindControl("DropDownList1")

   If Not cntl Is Nothing Then
       DirectCast(cntl, DropDownList).Attributes.Add("onmousedown", "MyJavaScriptSetCurrentValue(this)")
       DirectCast(cntl, DropDownList).Attributes.Add("onchange", "MyJavaScriptConfirmFunction(this)")
   End If
End If

 

Now you javascript would be something like:

var curValue;

function MyJavaScriptSetCurrentValue(cntl)
{
     curValue = cntl.value;
}
function MyJavaScriptConfirmFunction(cntl, currentValue)
{
     if(confirm('Are you sure?'))
        return;
     else
        cntl.value = curValue;
}

 

***Note this may not be the best method but it will get the job done...you might want to take the time to do something a little more robust like setting a hidden input tag to the current value that has a similiar name, or something like that.

 

Hope this helps.

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.

×
×
  • Create New...