I have the same issue as that of a previous poster in which I need to set a session variable prior to page load. Because pageload fires before my gridview.RowCommand, I am trying to use this method found in the article below which incorporates the use of a hiddenfield. My ultimate goal is to remove the onRowCommand event and to use the solution presented in the article. I have been using firebug to debug my javascript but everytime I get an error "is undefined" when I look at this.parent (this is a td and this.parent should be the tr). According to firebug, this.parent.cells[2].textContent is how I get to the OID value I want. As I spend little time writing javascript, any help would be very much appreciated.
Problem Line of Code from JS
this.parent.cells[2].textContent
My GridView
<asp:GridView ID="gridViewOpenOrders" CssClass="gvOpenOrders" runat="server" AutoGenerateColumns="False"
AllowPaging="True" RowStyle-BorderStyle="None"
DataKeyNames="AccountNumber,OrderID"
Width="802px" OnRowCommand="gridViewOpenOrders_RowCommand">
<Columns>
<asp:ButtonField Text="Select" HeaderStyle-Width="40px" ItemStyle-CssClass="assignOrderID"/>
<asp:BoundField DataField="OrderDate" HeaderText="Date" SortExpression="OrderDate"
DataFormatString="{0:d}">
<HeaderStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="OrderID" HeaderText="OID" SortExpression="OrderID">
<HeaderStyle Width ="40px" />
</asp:BoundField>
</Columns>
<HeaderStyle CssClass="ColumnHeaders" />
<RowStyle CssClass="ColumnRows" />
<SelectedRowStyle BackColor="#D9D9FF" />
</asp:GridView>
My Javascript:
<script type="text/javascript">
$(document).ready(function() {
$(".assignOrderID").click(function () {
var testing = $(".assignOrderID")
alert(this.parent)
alert(this.parent.cells[2])
alert(this.parent.cells[2]).textContent
document.getElementById('ContentPlaceHolder1_formViewOrder_hiddenFieldOrderID').value = this.parent.cells[2].textContent
alert('hi2');
});
});
</script>
Page Load Code:
Dim t As HiddenField = formViewOrder.FindControl("hiddenFieldOrderID")
Session.Add("OrderID", t.Value)
Research: Setting a session variable before AutoPostBack fires in an asp:Button