Link to home
Start Free TrialLog in
Avatar of suran78
suran78

asked on

Datagrid question

Experts,

I need Asp.net/VB.net code for this task.  I have 2 dropdowns.  These dropdown are interconnected to each other such that if a block_no is selected the second dropdown will show all the products in the selected block.  This part is done.  The next step is to display a editable table of data, i.e,
1.  If block_no is selected and nothing is selected in the product dropdown then all products in that block show up in the datagrid with edit column in each row.  

2. If block_ no is selected and product is selected then only that product show up in the datagrid with edit coulmn

3. I need code for editing each row in teh datagrid too.

Please help me.  Here is the dropdown codes that is working:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        If Not IsPostBack Then
            BuildBlockDropDown()
        End If
     
    End Sub

Private Sub BuildBlockDropDown()
        Dim dsBlockNo As DataSet
        dsBlockNo = ExecuteDataset(AppSettings("DB_CONNECTION_STRING"), CommandType.Text, "Select Block_no from Plant")
        If HasRows(dsBlockNo) Then
            BuildDropDown(DropDownList1, dsBlockNo, "Block_No", "Block_No", "Select Block No", "", False)
        End If
        DropDownList1.SelectedIndex = 0
    End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

        BuildSeriesDropDown()

    End Sub

Private Sub BuildSeriesDropDown()
        Dim dsSeriesNo As DataSet
        Dim sKey As String = DropDownList1.SelectedItem.Value.ToString()
        dsSeriesNo = ExecuteDataset(AppSettings("DB_CONNECTION_STRING"), CommandType.Text, "SELECT DISTINCT Series_no FROM Cell_series where Block_no = " & sKey)
        If HasRows(dsSeriesNo) Then
            BuildDropDown(DropDownList2, dsSeriesNo, "Series_No", "Series_No", "Select Series No", "", False)
        End If
        DropDownList2.SelectedIndex = 0

    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Rejojohny
Rejojohny
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of suran78
suran78

ASKER

but when Block_no is selecetd in dropdown1, the datagrid become visible.  Again when the product is selceted from the second drill down list the datagrid shows 1 record.  

Also each row should have edit button and when the user hits edit, the label on the edit button changes to "Update". When the user clicks update, only that record is updated.  Do I still need to loop through all records ?  

 
>>Also each row should have edit button and when the user hits edit, the label on the edit button changes to "Update". When the user clicks update, only that record is updated.  Do I still need to loop through all records ?

if that is the case, then there is no need to loop .. add the textbox in the editTemplate section of the datagrid and also add the buttons for edit,update, cancel (right click the datagrid and go to property builder and add these buttons) .. have a look here for an example for doing all the above ..
http://authors.aspalliance.com/das/editdatagrid.aspx
http://authors.aspalliance.com/aldotnet/examples/datagrideditddlvb.txt


Avatar of suran78

ASKER

Do you know what does this error mean:

Columns is not a member of abc.datagrid
what is abc? R u not using the standard datagrid that comes with VS.net? I think this error means that "columns" is not a method/property of abc.datagrid
Avatar of suran78

ASKER

The previous error is gone now.  But I am getting this new error , "per the active schema, the element "asp:textbox:" cannot be nested within 'columns' " on this line

<ASP:TextBox id="txtTitle" runat="server" Text='<%# Container.DataItem("Series_no") %>'></ASP:TextBox>

There is no syntax error then what does this error mean ?
Avatar of suran78

ASKER

Getting this, please help

Exception Details: System.InvalidCastException: Specified cast is not valid.

Sub DoItemUpdate(objSource As Object, objArgs As DataGridCommandEventArgs)

   'get a reference to the title and publication date text boxes
   Dim objTitleCtrl, objPubDateCtrl As TextBox
   objTitleCtrl = CType(objArgs.Item.FindControl("txtTitle"), TextBox)<---------------Error
   objPubDateCtrl = objArgs.Item.Cells(2).Controls(0)<-------------------------------Error

   'create a suitable SQL statement and execute it
   Dim strSQL As String
   strSQL = "UPDATE Booklist SET Title='" & objTitleCtrl.Text & "', " _
          & "PublicationDate='" & objPubDateCtrl.Text & "' " _
          & "WHERE ISBN='" & MyDataGrid.DataKeys(objArgs.Item.ItemIndex) & "'"
   ExecuteSQLStatement(strSQL)

   'set EditItemIndex property of grid to -1 to switch out of Edit mode
   MyDataGrid.EditItemIndex = -1
   BindDataGrid()  'bind the data and display it

End Sub