Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

What type of column to use?

Posted on 2005-04-11
3
Medium Priority
?
185 Views
Last Modified: 2010-04-17
Hi,

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?

Thanks,
Aruna
0
Comment
Question by:arunatata
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
netcool earned 1500 total points
ID: 13759420
Hi

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"
else
  Adodc1.recordsource  = "select Date,status from table"
end if
adodc1.refresh

check this out.
0
 

Author Comment

by:arunatata
ID: 13759527
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
            DG.Columns.Add(BtnCol)
            DG.DataBind()

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?

Thanks,
A.
0
 

Author Comment

by:arunatata
ID: 13759701
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)
            myConn.Open()
            Dim myDR As SqlDataReader
            myDR = myCmd.ExecuteReader
            ListDocs.DataSource = myDR
            ListDocs.DataTextField = "DocName"

            ListDocs.DataBind()

            myDR.Close()
        myConn.Close()
 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.Columns.Add(BtnCol)
            DG.Attributes.Add("OnitemCommand", "DG_Update")

            DG.DataBind()
            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
'THIS SUB IS NOT FIRING

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

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

577 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