farjack1
asked on
GridView problem under not ispostback
i have a grid and its working fine in grid i have Edit and Delete button, its working fine if i put the gridview code in GridView_Load event, if i put my code under
If Not IsPostBack Then
End If
then i press the Edit button then page postback and get blank since i am putting the data in session and binding grid again with session variable
Please suggest
Thanks
If Not IsPostBack Then
End If
then i press the Edit button then page postback and get blank since i am putting the data in session and binding grid again with session variable
Please suggest
Thanks
we need code... actually you dont need to put data in session, it should be already in viewstate, no need to bind again...
yes we need code, however,
If Not IsPostBack Then
End If
means if the page is not trigger the postback, and if you put this statement in page_load, after you click the EDIT button, since the EDIT button will trigger the postback, therefore every code inside of this IF statement will not run
If Not IsPostBack Then
End If
means if the page is not trigger the postback, and if you put this statement in page_load, after you click the EDIT button, since the EDIT button will trigger the postback, therefore every code inside of this IF statement will not run
ASKER
markup
<asp:GridView ID="testGridView" runat="server" AutoGenerateColumns="False "
EnableViewState="False">
<Columns>
<asp:BoundField DataField="gvOrderID" HeaderText="OrderID" ReadOnly="True"/>
<asp:TemplateField HeaderText="ProductName">
<ItemTemplate>
<asp:Label id="labelProductName" runat="server" text='<%# Bind("gvProductName") %>'>></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlProductName" runat="server"
DataTextField="ProductName " DataValueField="ID" DataSource="<%# loadProducts %>" />
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="gvUnitPrice" HeaderText="UnitPrice" ReadOnly="True" SortExpression="UnitPrice" />
<asp:BoundField DataField="gvQuantity" HeaderText="Quantity" ReadOnly="true" SortExpression="Quantity" />
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:Button id="btnEdit" runat="server" Text="Edit" CommandName="Edit" />
<asp:Button id="btnDelete" runat="server" Text="Deate" CommandName="Delete" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button id="btnUpdate" runat="server" Text="Update" CommandName="Update"/>
<asp:Button id="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
If Not IsPostBack Then
loadProducts()
loadOrderGridData
End If
End Sub
Private Sub loadOrderGridData()
Dim NewRow As DataRow
Dim table As DataTable = New DataTable("OrderDetail")
Dim colItemOrderID As DataColumn = New DataColumn("gvOrderID", Type.GetType("System.Strin g"))
Dim colItemProductID As DataColumn = New DataColumn("gvProductID", Type.GetType("System.Strin g"))
Dim colItemProductName As DataColumn = New DataColumn("gvProductName" , Type.GetType("System.Strin g"))
Dim colItemUnitPrice As DataColumn = New DataColumn("gvUnitPrice", Type.GetType("System.Strin g"))
Dim colItemQty As DataColumn = New DataColumn("gvQuantity", Type.GetType("System.Strin g"))
table.Columns.Add(colItemO rderID)
table.Columns.Add(colItemP roductID)
table.Columns.Add(colItemP roductName )
table.Columns.Add(colItemU nitPrice)
table.Columns.Add(colItemQ ty)
ordDetailList = objOrderMapper.getOrder()
For i = 0 To ordDetailList.Count - 1
NewRow = table.NewRow()
NewRow("gvOrderID") = CType(ordDetailList.Item(i ), Order).OrderID 'testGridView.Rows(i).Cell s(0).Text
'gvLabelProduct = DirectCast(DirectCast(send er, GridView).Rows(i).FindCont rol("ddlPr oductName" ), Label)
NewRow("gvProductName") = CType(ordDetailList.Item(i ), Order).ProductName 'gvLabelProduct.Text
NewRow("gvUnitPrice") = CType(ordDetailList.Item(i ), Order).Quantity 'testGridView.Rows(i).Cell s(2).Text
NewRow("gvQuantity") = CType(ordDetailList.Item(i ), Order).UnitPrice 'testGridView.Rows(i).Cell s(3).Text
table.Rows.Add(NewRow)
Next
'Dim dvData As DataView = New DataView(table)
Session("OrderTable") = table
BindData()
End Sub
Private Sub BindData()
Me.testGridView.DataSource = Session("OrderTable")
Me.testGridView.DataBind()
End Sub
Function loadProducts() As IList
prdList = objOrderMapper.getProducts ()
Return prdList
End Function
<asp:GridView ID="testGridView" runat="server" AutoGenerateColumns="False
EnableViewState="False">
<Columns>
<asp:BoundField DataField="gvOrderID" HeaderText="OrderID" ReadOnly="True"/>
<asp:TemplateField HeaderText="ProductName">
<ItemTemplate>
<asp:Label id="labelProductName" runat="server" text='<%# Bind("gvProductName") %>'>></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlProductName" runat="server"
DataTextField="ProductName
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="gvUnitPrice" HeaderText="UnitPrice" ReadOnly="True" SortExpression="UnitPrice"
<asp:BoundField DataField="gvQuantity" HeaderText="Quantity" ReadOnly="true" SortExpression="Quantity" />
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:Button id="btnEdit" runat="server" Text="Edit" CommandName="Edit" />
<asp:Button id="btnDelete" runat="server" Text="Deate" CommandName="Delete" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button id="btnUpdate" runat="server" Text="Update" CommandName="Update"/>
<asp:Button id="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
If Not IsPostBack Then
loadProducts()
loadOrderGridData
End If
End Sub
Private Sub loadOrderGridData()
Dim NewRow As DataRow
Dim table As DataTable = New DataTable("OrderDetail")
Dim colItemOrderID As DataColumn = New DataColumn("gvOrderID", Type.GetType("System.Strin
Dim colItemProductID As DataColumn = New DataColumn("gvProductID", Type.GetType("System.Strin
Dim colItemProductName As DataColumn = New DataColumn("gvProductName"
Dim colItemUnitPrice As DataColumn = New DataColumn("gvUnitPrice", Type.GetType("System.Strin
Dim colItemQty As DataColumn = New DataColumn("gvQuantity", Type.GetType("System.Strin
table.Columns.Add(colItemO
table.Columns.Add(colItemP
table.Columns.Add(colItemP
table.Columns.Add(colItemU
table.Columns.Add(colItemQ
ordDetailList = objOrderMapper.getOrder()
For i = 0 To ordDetailList.Count - 1
NewRow = table.NewRow()
NewRow("gvOrderID") = CType(ordDetailList.Item(i
'gvLabelProduct = DirectCast(DirectCast(send
NewRow("gvProductName") = CType(ordDetailList.Item(i
NewRow("gvUnitPrice") = CType(ordDetailList.Item(i
NewRow("gvQuantity") = CType(ordDetailList.Item(i
table.Rows.Add(NewRow)
Next
'Dim dvData As DataView = New DataView(table)
Session("OrderTable") = table
BindData()
End Sub
Private Sub BindData()
Me.testGridView.DataSource
Me.testGridView.DataBind()
End Sub
Function loadProducts() As IList
prdList = objOrderMapper.getProducts
Return prdList
End Function
what is this doing? loadProducts is a function and used like a sub...
Function loadProducts() As IList
prdList = objOrderMapper.getProducts ()
Return prdList
End Function
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
If Not IsPostBack Then
loadProducts() >>>>>>>>>>> ????? <<<<<<<<<<<
End If
End Sub
Function loadProducts() As IList
prdList = objOrderMapper.getProducts
Return prdList
End Function
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
If Not IsPostBack Then
loadProducts() >>>>>>>>>>> ????? <<<<<<<<<<<
End If
End Sub
;) got it, you can remove this line
and also why it is form1_Load, should not it be Page_Load?
and also why it is form1_Load, should not it be Page_Load?
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
If Not IsPostBack Then
loadOrderGridData()
End If
End Sub
maybe you turned off your viewstate... thats why you get nothing...
do you have anything like this
EnableViewState="false"
in page/form or web config?
do you have anything like this
EnableViewState="false"
in page/form or web config?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.