What type of column to use?

Posted on 2005-04-11
Last Modified: 2010-04-17

I have a datagrid with data columns "Date" and "status" for a particular document. I'd like to include a third button column called "reserve". I want this column to show up only if the status for the document is set to "Available". When the user clicks the button in a row, I don't want the datagrid to become editable. Instead all it should do is update the database and set the status for that particular row to "Checked out" and refresh the datagrid.

My problem is that I am not sure what kind of column i should use for this. A template column or a button column? Also how can I do the above using this column?

Question by:arunatata
    LVL 5

    Accepted Solution


    i can give solution for you. Can you give me your code that use DataGrid.

    if u dont want the user to edit the datagrid, right click the datagrid and select property pages and set AllowEdit to false. Goto Spilts and set AllowFocus to False.

    r u using Adodc to bind the database to DataGrid.

    before u display the datagrid control validate your field status = "Avaliable"

    then update you reserve field in the database the bring the data to datagrid

    if status = "reserve" then
       Adodc1.recordsource = "select Date,Status,reserve from table"
      Adodc1.recordsource  = "select Date,status from table"
    end if

    check this out.

    Author Comment

    Hi Netcool,

    My datagrid has autogenerated columns and I added a button column in addition to those. The datagrid thus now has 3 columns

    ButtonCol                  Date                      Status
    Reserve                     4/17/05                  Available
    Reserve                     4/18/05                  Available
                                      4/19/05                Unavailable

    The code for the datagrid itself is a whole different story. I created a datatable, flipped the columns and then bound them to the datagrid. I then programatically added the buttoncolumn using the following code:

                Dim BtnCol As New ButtonColumn
                With BtnCol
                    .Text = "Reserve "
                    .CommandName = "DG_Update(" & DocName & "," & ReservedDate & ")"
                    .HeaderText = "Action"
                End With

    All the above code created the datagrid shown above. As you can see, the commandname for the ButtonColumn has two parameters - DocName and ReservedDate.

    Now whenever someone clicks on "Reserve" in the datagrid, I want it to go ahead and update the database with the status for that date set to "Unavailable". It should then update the datagrid with the fresh data.

    My problem here is I don't know how to get the parameters from this code to the other sub "DG_Update" where the update function is being called.  The itemcommand event needs DocName and ReservedDate as inputs. How do I pass these to it? And is the method I am following above correct?


    Author Comment

    Actually moved a little further on this - I used viewstate to store the values of DocName and ReservedDate and am calling them from the same when the itemcommand event fires. However the itemcommand event is NOT firing. Please help!!

    The structure of the page is as below:

    It has two listboxes and a button. The button_click event take the values of the listboxes and uses them to query the database and print out a datagrid.

    Sub Page_load
            If Not Page.IsPostBack Then
    'Bind data from a table to the listbox
                Dim mainConnString As String = "Data Source=biginfo;Initial Catalog=aruna;User ID=sa"
                Dim myConn As New SqlConnection(mainConnString)
                Dim QueryString As String = "SELECT DocName FROM DocReserveDetail a INNER JOIN DocDetail b ON a.DocID = b.DocID"
                Dim myCmd As New SqlCommand(QueryString, myConn)
                Dim myDR As SqlDataReader
                myDR = myCmd.ExecuteReader
                ListDocs.DataSource = myDR
                ListDocs.DataTextField = "DocName"


     End If
    End sub

    Sub button_click
    if page.ispostback then
    'get values for DocName and Date
    'Get dataset from getDataset() and bind to the datagrid
    'add buttoncolumn to the datagrid
                Dim myDV As DataView = getDataset(DocName, newDate).Tables(0).DefaultView

                DG.DataSource = myDV
                Dim BtnCol As New ButtonColumn
                With BtnCol
                    .Text = "Reserve "
                    .CommandName = "DG_Update"
                    .HeaderText = "Action"
                End With
                DG.Attributes.Add("OnitemCommand", "DG_Update")

                ViewState("DocName") = DocName
                ViewState("newDate") = newDate
    end if
    end sub

    Sub getDataset()
    'Get values from database and bind
    end sub

    Sub DG_Update(byval sender as object, byval e as datagridcommandeventargs) handles dg.itemcommand

    Dim testername as string = convert.tostring(Viewstate("Testername"))
    Dim newDate as string = convert.tostring(ViewState("newDate"))
    end sub


    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    This is an explanation of a simple data model to help parse a JSON feed
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now