Results 1 to 10 of 10

Thread: [2005] gridview problems

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    37

    [2005] gridview problems

    i have two problems while using gridview.
    1st is i want to make a total amount in my gridview like this


    how can i do that? i already stuck at that

    the my 2nd problem is i want to edit my gridview like this





    i already used the <asp:itemtemplate> n <asp:edititemtemplate> but still it won't work. so is something wrong in my code?

    thx before
    Attached Images Attached Images    

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: [2005] gridview problems

    Can you be more specific about your problem? Is it erroring somewhere or just not working?

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    37

    Re: [2005] gridview problems

    thx for the reply.

    i assume that u are asking my 2nd problem, yea.. it is not working. i don't get any error in that.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] gridview problems

    For 2, you want to use the EditItemTemplate, but you've not given any more info aside from what you want. Show code.

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    37

    Re: [2005] gridview problems

    thx for the reply n here is my gridview code

    HTML Code:
    <asp:GridView ID="GridView1" HeaderStyle-CssClass=".viewgrid1_header" AutoGenerateEditButton="true" AutoGenerateSelectButton="true" AllowPaging="True" OnPageIndexChanging="changing" AutoGenerateColumns="False" runat="server" >
            <HeaderStyle BackColor="#D9D9D9" CssClass="viewgrid1_header" HorizontalAlign="Center" Font-Bold="True" />
            <RowStyle BackColor="#ECECEC" />
            <AlternatingRowStyle BackColor="White"/>
            
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" InsertVisible="False" />
                <asp:BoundField DataField="EMPLID" HeaderText="EMPLID" InsertVisible="False" ReadOnly="True" SortExpression="EMPLID" />
                <asp:TemplateField HeaderText="List">
                <ItemTemplate><asp:Label ID="lbl" runat="Server"></asp:Label></ItemTemplate>
                <EditItemTemplate><asp:DropDownList ID="ddl" runat="server"></asp:DropDownList> </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                <ItemTemplate><asp:Label ID="lbl1" runat="server"><%#Eval("Status")%></asp:Label></ItemTemplate>
                <EditItemTemplate>
                <asp:DropDownList ID="ddl1" runat="Server">
                <asp:ListItem>tes</asp:ListItem>
                <asp:ListItem>in progress</asp:ListItem>
                <asp:ListItem>approved</asp:ListItem>
                <asp:ListItem>rejected</asp:ListItem>
                </asp:DropDownList>
                </EditItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Leave_Type" HeaderText="Leave_Type" SortExpression="Leave_Type" />
                <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
                <asp:BoundField DataField="Start_Date" HeaderText="Start_Date" SortExpression="Start_Date" />
                <asp:BoundField DataField="End_Date" HeaderText="End_Date" SortExpression="End_Date" />
            </Columns>        
            
            <PagerStyle HorizontalAlign="Right" BorderStyle="None" BorderColor="White" ForeColor="Orange"/>
            <PagerSettings Mode="NumericFirstLast" FirstPageText="First" LastPageText="Last" Position="Top"/>
            </asp:GridView>
    and here is my code behind
    Code:
    Private Sub ConnectDB()
            Dim con As SqlConnection
            Dim com As SqlCommand
            Dim adapter As New SqlDataAdapter
            Dim dset As New Data.DataSet
            Dim sql, table As String
    
            sql = "select * from TrLeaveRequest"
            table = "TrLeaveRequest"
    
            con = New SqlConnection("server=(local);uid=work;pwd=123456;database=work")
            con.Open()
    
            com = New SqlCommand(sql, con)
    
            adapter.SelectCommand = com
            adapter.Fill(dset, Table)
    
            GridView1.DataSource = dset
            GridView1.DataBind()
    
            con.Close()
    
        End Sub
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            ConnectDB()
    
        End Sub
    
        Protected Sub changing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
            GridView1.PageIndex = e.NewPageIndex
            ConnectDB()
        End Sub
    
        Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
    
        End Sub
    
        Protected Sub GridView1_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles GridView1.SelectedIndexChanging
            Dim index As Integer
    
            index = e.NewSelectedIndex
    
            TextBox1.Text = GridView1.Rows(index).Cells(1).Text
        End Sub
    so is there anything wrong with my code?

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] gridview problems

    So at first glance, this seems fine. You should be able to enter edit mode with those edit controls in place.

    What then is the problem? Try to be more specific than "still it won't work".

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    37

    Re: [2005] gridview problems

    when i pressed the edit button it does nothing. the gridview don't change into editable control.

    could there be any possibility that my vs2005 that is went wrong?
    Last edited by AeroConfident; Aug 6th, 2007 at 05:48 AM.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] gridview problems

    The first question for you would be, did you set it up right? In order to verify that you have set it up right, compare what you did with this MSDN article...
    http://msdn2.microsoft.com/en-us/library/ms972948.aspx

  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    37

    Re: [2005] gridview problems

    from the link above, looks like i need an update command n update parameter, is that right?

    coz both sqldatasource n objectdatasource has those command

    Code:
            <asp:SqlDataSource ID="productDataSource" Runat="server"
                SelectCommand="SELECT [ProductName], [ProductID], 
                [UnitPrice], [UnitsInStock] FROM [Products]"
                UpdateCommand="UPDATE [Products] SET [ProductName] = 
                  @ProductName, [UnitPrice] = @UnitPrice, [UnitsInStock] = 
                  @UnitsInStock WHERE [ProductID] = @original_ProductID"
                ConnectionString="<%$ ConnectionStrings:NWConnectionString %>">
                <UpdateParameters>
                    <asp:Parameter Type="String" 
                      Name="ProductName"></asp:Parameter>
                    <asp:Parameter Type="Decimal" 
                      Name="UnitPrice"></asp:Parameter>
                    <asp:Parameter Type="Int16" 
                      Name="UnitsInStock"></asp:Parameter>
                    <asp:Parameter Type="Int32" Name="ProductID"></asp:Parameter>
                </UpdateParameters>
            </asp:SqlDataSource>

    Code:
            <asp:ObjectDataSource ID="productDataSource" 
                Runat="server" TypeName="ProductDAL"
                SelectMethod="GetProducts" EnablePaging="True" 
                SelectCountMethod="TotalNumberOfProducts"
                UpdateMethod="UpdateProduct">
                <UpdateParameters>
                    <asp:Parameter Type="Int32" Name="ProductID"></asp:Parameter>
                    <asp:Parameter Type="String" 
                      Name="productName"></asp:Parameter>
                    <asp:Parameter Type="Decimal" 
                      Name="unitPrice"></asp:Parameter>
                    <asp:Parameter Type="Int32" 
                      Name="unitsInStock"></asp:Parameter>
                </UpdateParameters>
            </asp:ObjectDataSource>
    Last edited by AeroConfident; Aug 10th, 2007 at 04:05 AM.

  10. #10

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    37

    Re: [2005] gridview problems

    for the 1st problem instead of using gridview, i use repeater.

    i don't find any clue about how to do that using gridview
    Last edited by AeroConfident; Aug 23rd, 2007 at 12:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width