Hello
I need to generate a postback when exit of a cell in RowAdding. I achieved something like this, with event RowUpdating. I did, in page aspx:
<asp:UpdatePanel runat="server" ID="SampleUpdatePanel"><ContentTemplate>
<ig:WebDataGrid ID="WebDataGrid1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyFields="OrderID" OnRowUpdating="WebDataGrid1_RowUpdating">
.
<Behaviors> <ig:Activation> </ig:Activation> <ig:EditingCore AutoCRUD="False"> <Behaviors> <ig:CellEditing> <CellEditingClientEvents ExitedEditMode="WebDataGrid1_CellEditing_ExitedEditMode" /> </ig:CellEditing> </Behaviors> </ig:EditingCore> <ig:Selection CellClickAction="Row" RowSelectType="Single"> </ig:Selection> <ig:RowSelectors> </ig:RowSelectors></Behaviors>
</ig:WebDataGrid>
</ContentTemplate></asp:UpdatePanel>
<script type="text/javascript">function WebDataGrid1_CellEditing_ExitedEditMode(sender, eventArgs) {
__doPostBack('<%= SampleUpdatePanel.ClientID %>', '');}
</script>
Therefore, with this, it generates a postback every time it exits to edit a cell (any cell, not necessarily the whole row) and enters in the following event:
protected void WebDataGrid1_RowUpdating(object sender, RowUpdatingEventArgs e){
//My code
}
This is okay, because it's just what I need.
Now, I need to make the same, but in this case, in a RowAdding event. I did something like this, in page aspx:
<ig:WebDataGrid ID="WebDataGrid1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyFields="OrderID" OnRowUpdating="WebDataGrid1_RowUpdating" OnRowAdding="WebDataGrid1_RowAdding">
<Behaviors>
<ig:Activation> </ig:Activation> <ig:EditingCore AutoCRUD="False"> <Behaviors> <ig:CellEditing> <CellEditingClientEvents ExitedEditMode="WebDataGrid1_CellEditing_ExitedEditMode" /> </ig:CellEditing> <ig:RowAdding> <AddNewRowClientEvents ExitedEditMode="WebDataGrid1_RowAdding_ExitedEditMode" /> </ig:RowAdding> </Behaviors> </ig:EditingCore> <ig:Selection CellClickAction="Row" RowSelectType="Single"> </ig:Selection> <ig:RowSelectors> </ig:RowSelectors></Behaviors>
function WebDataGrid1_RowAdding_ExitedEditMode(sender, eventArgs) { __doPostBack('<%= SampleUpdatePanel.ClientID %>', ''); }
But, in this case, it generates a postback (I know it because put a breakpoint in Page_Load()) every time it exits of a cell (in The last row is used to insert or add), that's ok, but NOT enters in the following event:
protected void WebDataGrid1_RowAdding(object sender, RowAddingEventArgs e){//My code}
I need to enter into this event each time it leaves of a cell (not whole row) within the row to add (in The last row is used to insert or add). What is happened? Why in this case, not enter in the event WebDataGrid1_RowAdding()?Can you help me, please? Any suggestions?
Thanks.Geovanny Domínguez
Hello Vasya
I have tried to make a sample project like my scenario. Please test this project on your PC, select the first option in the DropDownList then clic on the button. You can click on any cell and get out of this (excluding the cells in the Year column and I don't understand, Why is this happening?) and you'll watch that does not execute any postback to server side. Then you can edit one cell and afterwards you will watch when you do to click on any cell and exit ot this, the WebDataGrid will always execute a postback.
In the Default.aspx page, in GridViewData_CellEditing_ExitedEditMode function script, you can comment the line inside "if structure", remove the comment from the other line and you'll see what happens. What is the correct way to implement this?
Please, Could you help me? and, Why in the Year column is this happening?
Thanks.
Geovanny Domínguez.
I'm using your suggestion, I'm defining a global variable to use it as a flag for any changes made in the cell and finally in ExitingEditMode to check the value of the flag and do postback if necessary:
function GridViewData_CellEditing_ExitedEditMode(webDataGrid, eventArgs) { if (changes) {__doPostBack('<%= UpdatePanelMaster.ClientID %>', ''); } }
But with this, the first time works perfect, but when I modify any cell, that's ok, It triggers a postback and does commit operations to DataBase. Far so good. Afterwards the WebDataGrid no longer behaves the same way. Each time I pass the cursor on a cell (GridViewData.Behaviors.EditingCore.Behaviors.CellEditing.EditModeActions.MouseClick = EditMouseClickAction.Single;) and not edit anything, It always executes a call to the server. It seems to make a __doPostBack('<%= UpdatePanelMaster.ClientID %>', ''); is wrong.
Before making an edition, the WebDataGrid behaves as desired, but then it calls to the GridViewData_CellEditing_ExitedEditMode(...) function and enters to __doPostBack('<%= UpdatePanelMaster.ClientID %>', ''); line, its behavior changes.
I've tried with the following:
function GridViewData_CellEditing_ExitedEditMode(webDataGrid, eventArgs) {if (changes) { //__doPostBack('<%= UpdatePanelMaster.ClientID %>', ''); webDataGrid.get_behaviors().get_editingCore()._commitUpdates(); } }
With this apparently the WebDataGrid still works like before editing.
But, I'm not sure if this is correct... I would like something like in GridViewData_RowAdding_ExitedEditMode(...) function:
function GridViewData_RowAdding_ExitedEditMode(webDataGrid, eventArgs) {//Make a postback every time when some text is added in the new rows' cell
var newText = eventArgs.getCell().get_text(); if (newText !== "" && newText != null ) { var grid = webDataGrid; grid.get_behaviors().get_editingCore().get_behaviors().get_rowAdding()._commitRow(); } }
Can you help me, please? Any suggestion?
Hello Geovanny,
I am glad that you have been able to resolve your issue. If you need any further support do not hesitate to contact me.
Hello Vasya,
Yeah, It is what I needed. You're friendly.
Thank you very much.
I assume that your requirement is to make a postback every time when some text is added in the new rows` cell.
What I can suggest is handle the RowAdding_ExitedEditMode event where you can check whether any data is entered in the cell and make a postback if the cell is not empty . For example:
function WebDataGrid1_RowAdding_ExitedEditMode(sender, eventArgs) { var newText = eventArgs.getCell().get_text(); if (newText !== "") { __doPostBack('<%= SampleUpdatePanel.ClientID %>', ''); } }
function WebDataGrid1_RowAdding_ExitedEditMode(sender, eventArgs) {
var newText = eventArgs.getCell().get_text();
if (newText !== "") {
__doPostBack('<%= SampleUpdatePanel.ClientID %>', '');
Do not hesitate to contact me if you have any additional questions regarding this matter.