• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

What type of column to use?


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?

  • 2
1 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.
arunatataAuthor Commented:
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?

arunatataAuthor Commented:
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now