Hi everyone,
I hope you can help me with this, I am super new with web developing (I'm a VB.net developer) new to JavaScript and ASP.net, here is my issue, I have a WebDataGrid with four columns:
1- Reference No (Bounded Field from SqlDataSource)
2- Status (Bounded Field from SqlDataSource)
3- TemplateField with a buttom called (Approve)
4- TemplateField with a buttom called (Reject)
so what I want is when I click one of the buttons an SQL command will be fired to update the database, the problem that I couldn't get the column(Reference No) value of the clicked row to execute the query, so I need something like this:
"update Table set status="Approved" where ref_no=(ClickedRowIndex.Cell(Reference No).value)"
thanks in advance,
UPDTAE:
I managed to find a way to get the selected row index and it value, but the problem that I am facing now is when I click the button the selected row doesn't change (doesn't get focused), I have to click on any cell except the button to get a selected row and then I have to click the button, is there any way to set the selected row when the button is clicked?
Hi Osama,
Thank you for posting in our community.
You can try a different approach to achieve the required by enabling the Activation behavior of the WebDataGrid. In this case in the onClick handler of the button the Reference No can be accessed via the Items collection. For example:
protected void Approve_Click(object sender, EventArgs e){ var ref = grid.Behaviors.Activation.ActiveCell.Row.Items.FindItemByKey("Reference No").Value;}
This way you won't have issues with focusing the row.
Kind regards,Martin
Hi Martin,
Thank you for your reply, but I am sorry this method didn't work for me, I have Enabled the Activation behaviors as the below:
and I'm still unable to get the selected row when I click on the button,the code you provided is working only if I click on any cell as I mentioned in my post, and here is my selection behavior setting:
is there any extra setting on Activation Behaviors I should do?
Attached you will find a small sample reproducing the described behavior.
When the Approve button in the TemplateField is clicked, in the onClick event handler the row is directly retrieved without being clicked before that.
Please test it on your side and let me know how it behaves. If this is not an accurate demonstration of what you are trying to achieve please feel free to modify it and send it back to me along with steps to reproduce.
8311.Sample.zip
Thank you so much, I found out that the problem was with the WebImageButton, the function is not working with Infragistics WebImageButton unless I click on the row, but with the regular button, the function working fine! any idea please?
here is my code, I created two columns, one for WebImageButton and one for the regular button with same OnClick code as below, as I told you the regular button is working fine, but the WebImageButton of Infragistics is not working:
Protected Sub WebImageButton1_Click(sender As Object, e As Infragistics.WebUI.WebDataInput.ButtonEventArgs) lmsg.Text = WebDataGrid7.Behaviors.Activation.ActiveCell.Row.Items.FindItemByKey("leaveref").Value.ToString End Sub Protected Sub Button1_Click1(sender As Object, e As EventArgs) lmsg.Text = WebDataGrid7.Behaviors.Activation.ActiveCell.Row.Items.FindItemByKey("leaveref").Value.ToString End Sub
I have added the WebImageButton control and when debugging the value in Visual Studio it is retrieved in the onClick handler. I have modified and attached the previous sample. Let me know if that solves your issue.
0081.Sample.zip
I am really sorry I forgot to mention that the problem is happening when I'm using a SqlDataSource as datasource for the WebDataGrid.
I have modified and attached the sample so the WebDataGrid uses SQL data source which connects to the Microsoft's Northwind database. I still cannot reproduce your issue.
Please test it on your side and let me know the result.
8156.Sample.zip