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_CONNE CTION_STRI NG"), CommandType.Text, "Select Block_no from Plant")
If HasRows(dsBlockNo) Then
BuildDropDown(DropDownList 1, dsBlockNo, "Block_No", "Block_No", "Select Block No", "", False)
End If
DropDownList1.SelectedInde x = 0
End Sub
Private Sub DropDownList1_SelectedInde xChanged(B yVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedInde xChanged
BuildSeriesDropDown()
End Sub
Private Sub BuildSeriesDropDown()
Dim dsSeriesNo As DataSet
Dim sKey As String = DropDownList1.SelectedItem .Value.ToS tring()
dsSeriesNo = ExecuteDataset(AppSettings ("DB_CONNE CTION_STRI NG"), CommandType.Text, "SELECT DISTINCT Series_no FROM Cell_series where Block_no = " & sKey)
If HasRows(dsSeriesNo) Then
BuildDropDown(DropDownList 2, dsSeriesNo, "Series_No", "Series_No", "Select Series No", "", False)
End If
DropDownList2.SelectedInde x = 0
End Sub
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
If HasRows(dsBlockNo) Then
BuildDropDown(DropDownList
End If
DropDownList1.SelectedInde
End Sub
Private Sub DropDownList1_SelectedInde
BuildSeriesDropDown()
End Sub
Private Sub BuildSeriesDropDown()
Dim dsSeriesNo As DataSet
Dim sKey As String = DropDownList1.SelectedItem
dsSeriesNo = ExecuteDataset(AppSettings
If HasRows(dsSeriesNo) Then
BuildDropDown(DropDownList
End If
DropDownList2.SelectedInde
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>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
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
ASKER
Do you know what does this error mean:
Columns is not a member of abc.datagrid
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
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 ?
<ASP:TextBox id="txtTitle" runat="server" Text='<%# Container.DataItem("Series
There is no syntax error then what does this error mean ?
ASKER
Getting this, please help
Exception Details: System.InvalidCastExceptio n: 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.FindCon trol("txtT itle"), TextBox)<---------------Er ror
objPubDateCtrl = objArgs.Item.Cells(2).Cont rols(0)<-- ---------- ---------- ---------E rror
'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(objArg s.Item.Ite mIndex) & "'"
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
Exception Details: System.InvalidCastExceptio
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.FindCon
objPubDateCtrl = objArgs.Item.Cells(2).Cont
'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(objArg
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
ASKER
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 ?