DataGrid: Carriage Return in HtmlInputText shall save row

  • Thread starter Wolfgang Schmidt
  • Start date
W

Wolfgang Schmidt

Hello,

I have several datagrids in my application. At the moment, data rows
which are in editmode can only be saved by clicking the corresponding
save button. I would like to add the function that users can save the
rows by hitting carriage return when they have done their entries in
HtmlInputText-boxes. At the moment, hitting carriage return simply
does a postback without calling the save-funktion.
Does anyone how that can be done?

Wolfgang
 
W

Wolfgang Schmidt

I have resolved this issue like this:

I've added some javascript to my aspx-File:

function Save() {
if (event.keyCode==13) {
event.returnValue=false;
event.cancel=true;
var id = '';
for (var j=0; j<window.document.forms[0].elements.length; j++) {
var str = window.document.forms[0].elements[j].name;
if (str.indexOf("HiddenEditItemIndex")>-1) {
id = window.document.forms[0].elements[j].value;
if (typeof(Page_ClientValidate) != 'function' ||
Page_ClientValidate()) __doPostBack('myDataGrid:_ctl' + id +
':_ctl3','');
}
}
}

Moreover, a HtmlInputHidden has to be added like this:
<input type="hidden" runat="server" id="HiddenEditItemIndex" />

The webcontrols which have to react to carriage returns must get a
further attribute: onkeypress="Save()"

In my code, the HiddenEditItemIndex gets filled when a row in the grid
is added or edited, e.g.:

protected void myDataGrid_OnEditCommand(object sender,
DataGridCommandEventArgs e) {
....
HiddenEditItemIndex.Value = (e.Item.ItemIndex + 2).ToString(); //
"+ 2" means index of button and has to be changed probably
}



Does someone know an easier way to solve this issue?

Wolfgang
www.epsit.de



Alvin Bruney said:
Your post went unanswered. Have you resolved this issue?

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Wolfgang Schmidt said:
Hello,

I have several datagrids in my application. At the moment, data rows
which are in editmode can only be saved by clicking the corresponding
save button. I would like to add the function that users can save the
rows by hitting carriage return when they have done their entries in
HtmlInputText-boxes. At the moment, hitting carriage return simply
does a postback without calling the save-funktion.
Does anyone how that can be done?

Wolfgang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top