Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 4th, 2005, 12:53 PM
Authorized User
 
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid oneditcommand postback issue.

Hi,
I have a problem with datagrid oneditcommand. When I click on edit link on the datagrid the datagrid disappers. It just displays the blank screen. What could be the problem. I appreciate your help.

Regards..

Private Sub Page_Load(sender as Object, e as EventArgs)handles mybase.load
    If Not Page.IsPostBack then
      BindData()
    End If
  End Sub

Sub dDatagrid_Edit(sender As Object, e As DataGridCommandEventArgs)handles dDatagrid.editcommand
    dDatagrid.EditItemIndex = e.Item.ItemIndex
    BindData()

    dDatagrid.ShowFooter = False
  End Sub

  Sub dDatagrid_Cancel(sender As Object, e As DataGridCommandEventArgs)handles dDatagrid.cancelcommand

    dDatagrid.EditItemIndex = -1
    BindData()

   dDatagrid.ShowFooter = True
  End Sub




 
Old February 4th, 2005, 02:26 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Please show your BindData() code.
 
Old February 4th, 2005, 02:39 PM
Authorized User
 
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply.
Here is the BindData() code.

Regards..

Sub BindData()
      Dim SQL as String = "SELECT ID, Category_Name, descirption WHERE ID <= 25"
    Dim resultsDataSet as New DataSet()
    Dim myDataAdapter as SqlDataAdapter = New SqlDataAdapter(strSQL, myConnection)
    myDataAdapter.Fill(resultsDataSet)
    dDatagrid.DataSource = resultsDataSet
    dDatagrid.DataBind()
End Sub


 
Old February 4th, 2005, 02:42 PM
Authorized User
 
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, There was a typo error.Here is the right one.
Regards..

Sub BindData()
      Dim strSQL as String = "SELECT ID, Category_Name, descirption WHERE ID <= 25"
    Dim resultsDataSet as New DataSet()
    Dim myDataAdapter as SqlDataAdapter = New SqlDataAdapter(strSQL, myConnection)
    myDataAdapter.Fill(resultsDataSet)
    dDatagrid.DataSource = resultsDataSet
    dDatagrid.DataBind()
End Sub


 
Old February 4th, 2005, 02:50 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

From what I can see this should work. Have you tried tracing the code in the degugger? Make sure your BindGrid() sub is being called once you click on the edit link. Let me know how you do.
 
Old February 4th, 2005, 03:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Can you post your HTML code?

 
Old February 4th, 2005, 03:31 PM
Authorized User
 
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help.I tried to debug and trace the code. It seems to be BindData() function not been called when I click on the 'Edit' link. If I take out the Page.IsPostBack condition it's displaying the records, but the function called twice. I don't think this is correct.

Regards..

 
Old February 4th, 2005, 04:09 PM
Authorized User
 
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<@page language="vb" autoeventwireup="false" codebehind="test.aspx.vb" inherits="project1.test"%>
<html>
<body>
<form runat="server">
    <asp:datagrid id="dDataGrid" runat="server"
        AutoGenerateColumns="False"

        OnEditCommand="dDatagrid_Edit"
        OnCancelCommand="dDatagrid_Cancel"
        OnUpdateCommand="dDatagrid_Update"
        OnItemCommand="dDatagrid_Insert"

        ShowFooter="True">

      <Columns>
        <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="OK" />
        <asp:TemplateColumn ItemStyle-Width="10%"
            ItemStyle-HorizontalAlign="Center" HeaderText="ID">
          <ItemTemplate>
            <%# Container.DataItem("ID") %>
          </ItemTemplate>

          <FooterTemplate>
            <asp:Button Text="Add" CommandName="Insert" runat="server" />
          </FooterTemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn HeaderText="Category">
          <ItemTemplate>
            <%# DataBinder.Eval(Container.DataItem, "CategoryName") %>
          </ItemTemplate>

          <EditItemTemplate>
            <asp:DropDownList runat="server" id="lstCategories"
                  DataValueField="ID" DataTextField="CategoryName"
                  DataSource='<%# GetCategories() %>'
                  SelectedIndex='<%# GetSelectedIndex(Container.DataItem("ID")) %>' />
          </EditItemTemplate>

             <FooterTemplate>
            <asp:DropDownList runat="server" id="lstCategoriesInsert"
                  DataValueField="ID" DataTextField="CategoryName"
                  DataSource='<%# GetCategories() %>'
                  AutoPostBack="True"
                  OnSelectedIndexChanged="LoadSecondList" />
          </FooterTemplate>

        </asp:TemplateColumn>

        <asp:TemplateColumn HeaderText="Description">
          <ItemTemplate>
            <%# Container.DataItem("Description") %>
          </ItemTemplate>

          <EditItemTemplate>
            <asp:TextBox runat="server" Text='<%# Container.DataItem("Description") %>'
                   Columns="80" />
          </EditItemTemplate>

          <FooterTemplate>
            <asp:DropDownList runat="server" id="lstFAQsByCategory"
                  DataValueField="ID" DataTextField="Description"
                  DataSource='<%# GetFAQsByCategory(-1) %>' />
          </FooterTemplate>
        </asp:TemplateColumn>
      </Columns>
    </asp:datagrid>
  </form>
</body>
</html>






Similar Threads
Thread Thread Starter Forum Replies Last Post
Postback issue while selecting a parameter sonusarojan Reporting Services 2 May 15th, 2007 09:41 PM
Postback issue while selecting a parameter sonusarojan BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 March 21st, 2007 01:30 AM
postback issue with drop downlists emachines ADO.NET 3 March 26th, 2005 01:36 PM
postback issue with drop downlists emachines General .NET 1 January 9th, 2005 09:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.