Datagrid button's EditCommand

tiffany

Well-known member
Joined
Aug 7, 2005
Messages
57
Programming Experience
1-3
Datagrid and matching input with db problem.

In webform there is a datagrid tool. In datagrid, we can add the bound column, button column and hyperlink column. When i add button column(Edit, update, cancel button) in datagird. How i'm i suppose to do to make the button column works? As in when i click on the button column it will bring me to another page. I need help please!


I have a 2nd qns, i allow the user to key in the year and the year will match with the database then retreive the info and display in the datagrid.

I have this code******

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

Dim key As String = TextBox1.Text

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Server.MapPath("movie.mdb")

Dim strSQL As String = "SELECT Title, Year FROM movieDet WHERE Year = 'key' "

Dim cmd As New OleDbCommand(strSQL, New OleDbConnection(strConn))

cmd.Connection.Open()

DataGrid1.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)

DataGrid1.DataBind()

cmd.Connection.Close()

cmd.Connection.Dispose()

End Sub

I try to run the program but it gave me an error "Data type mismatch in criteria expression. " in this line: "DataGrid1.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)"

How can i solve it? Help please! its urgent. Thankx.
 
Last edited:
Hi,

Regarding your second question, what is the dataype of year in your table. And you need to use the & symbol while formin the query.



Dim strSQL As String = "SELECT Title, Year FROM movieDet WHERE Year =' " & key & " ' "



Good Luck,
Reshma
 
Hi Reshma, I had tried the sentance. But there a little error. Instead Of & i use +.

Dim strSQL As String = "SELECT Title, Year FROM movieDet WHERE Year =' " + key + " ' "


regards,
tiffany
 
Update link button in datagrid

Hi! i had a problem with datagrid. I had add a update link button in the datagrid.
I use this code to activate my update link button;

Private Sub update_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles update.EditCommand

' Dim b As String = e.Item.Cells(0)

End Sub

But this code "e.Item.Cells(0)" seems to be has error.

Can help me slove this problem. Thankx.

regards,
tiffany
 
within the HTML source for the grid there are these events which are fired when a certain button is clicked

OnItemCommand
OnUpdateCommand
OnEditCommand
OnCancelCommand

so u set these to a public sub in the code behind

ie

HTML
OnItemCommand = "grd_GridItem"

CodeBehind
PublicSub grdGrid_Item(ByVal sender AsObject, ByVal e As DataGridCommandEventArgs)



End Sub
 
Hi sorry i had another qns, I had two datagrids in one webform. Datagrid1 and datagrid2. I create update link button in datagrid1, once i click on the update link button..it iwll retreive the data and display in datagrid2. I had this code in the datagrid1 link button:

Private Sub update_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles update.EditCommand

' Dim a As String = e.Item.Cells(0).Text

'Response.Redirect("updateList.aspx")

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Server.MapPath("movie.mdb")

If update.Columns.Selected Then

Dim strSQL As String = "SELECT Title, category FROM movieDet WHERE category = 'Horror' "

Dim cmd As New OleDbCommand(strSQL, New OleDbConnection(strConn))

cmd.Connection.Open()

DataGrid1.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)

DataGrid1.DataBind()

cmd.Connection.Close()

cmd.Connection.Dispose()

End If

End Sub

This line "update.Columns.Selected " has an error. How can improve the codes to display the data in datagrid2? Thankx. Urgent.

Regards,
tiffany
 
Last edited:
IN the commandargument of the link button that you created in data grid1 call the function that will be containing the code for displaying the data in data grid2 or you can place the code in the click event of the link button also. latter one is more justifiable.
 
Back
Top