Cells(2).Text returns an empty string
-
I have the following code in my application... Protected Sub gridTerms_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridTerms.RowDataBound Dim strMsg As String If (e.Row.RowType = DataControlRowType.DataRow) Then If (e.Row.FindControl("lnkDelete") IsNot Nothing) Then strMsg = "return confirm('Please confirm. Delete payment term " & Trim(e.Row.Cells(2).Text) & "?');" CType(e.Row.FindControl("lnkDelete"), LinkButton).OnClientClick = strMsg End If End If End Sub For some reason the contents of this cell (which is a code) appears blank in the debugger and the JavaScript confirm shows an empty string in the message. The GridView appears fine but even investigating the value of e.Row.Cells(2).Text in the debugger reveals an empty string. Any ideas??
-
I have the following code in my application... Protected Sub gridTerms_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridTerms.RowDataBound Dim strMsg As String If (e.Row.RowType = DataControlRowType.DataRow) Then If (e.Row.FindControl("lnkDelete") IsNot Nothing) Then strMsg = "return confirm('Please confirm. Delete payment term " & Trim(e.Row.Cells(2).Text) & "?');" CType(e.Row.FindControl("lnkDelete"), LinkButton).OnClientClick = strMsg End If End If End Sub For some reason the contents of this cell (which is a code) appears blank in the debugger and the JavaScript confirm shows an empty string in the message. The GridView appears fine but even investigating the value of e.Row.Cells(2).Text in the debugger reveals an empty string. Any ideas??
-
In my experience with this stuff, sometimes you get literal controls inbetween your actual controls in the cell. I am guessing that your text might be in cells(3) instead of cells(2). Just a stab in the dark. Hope that helps. Ben
Thanks for the reply. Actually, I investigated cells (0) through (4) in the debugger. All show empty strings, yet the GridView is populated with the propery data. This seems like it should be a no-brainer so it's really puzzling.
-
Thanks for the reply. Actually, I investigated cells (0) through (4) in the debugger. All show empty strings, yet the GridView is populated with the propery data. This seems like it should be a no-brainer so it's really puzzling.
You know when I have added confirm javascript type stuff to delete buttons, I have used a For Each loop in the gridview databound event. That way I can go through each datarow find the control and add the javascript. That sort of seems like what you are trying to do. Hope that helps. Ben
-
I have the following code in my application... Protected Sub gridTerms_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridTerms.RowDataBound Dim strMsg As String If (e.Row.RowType = DataControlRowType.DataRow) Then If (e.Row.FindControl("lnkDelete") IsNot Nothing) Then strMsg = "return confirm('Please confirm. Delete payment term " & Trim(e.Row.Cells(2).Text) & "?');" CType(e.Row.FindControl("lnkDelete"), LinkButton).OnClientClick = strMsg End If End If End Sub For some reason the contents of this cell (which is a code) appears blank in the debugger and the JavaScript confirm shows an empty string in the message. The GridView appears fine but even investigating the value of e.Row.Cells(2).Text in the debugger reveals an empty string. Any ideas??
Is this formatted text? I always had trouble getting the value from the cells that contained formatted text, maybe you should try to get the innerHTML.
Cleako
-
I have the following code in my application... Protected Sub gridTerms_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridTerms.RowDataBound Dim strMsg As String If (e.Row.RowType = DataControlRowType.DataRow) Then If (e.Row.FindControl("lnkDelete") IsNot Nothing) Then strMsg = "return confirm('Please confirm. Delete payment term " & Trim(e.Row.Cells(2).Text) & "?');" CType(e.Row.FindControl("lnkDelete"), LinkButton).OnClientClick = strMsg End If End If End Sub For some reason the contents of this cell (which is a code) appears blank in the debugger and the JavaScript confirm shows an empty string in the message. The GridView appears fine but even investigating the value of e.Row.Cells(2).Text in the debugger reveals an empty string. Any ideas??
Hai, what the method you are doing is correct. the same logic is to be used after the data binding of grid and not in the databound or row databound event. this way...
foreach (DataGridItem dgi in dg.Items) { // do the needed logic here }
really it works. Cheers asithangae -
Hai, what the method you are doing is correct. the same logic is to be used after the data binding of grid and not in the databound or row databound event. this way...
foreach (DataGridItem dgi in dg.Items) { // do the needed logic here }
really it works. Cheers asithangaeIf it is working why would he be posting a question?
Cleako
-
If it is working why would he be posting a question?
Cleako
He use this logic in rowdatabound event, i asked him to do the same after databind. i think you can know the difference. Cheers asithangae