i'm trying for hours to get a button in a datagrid. When clicked this button i
want to take a value of this table (movieName) and use it for redirection...
I've done some similar work before, but now it simply don't work... i don't know
what the reason is...
Also the editCommand & co doesn't work, i guess this is the same problem...
somebody can see what i'm doing wrong?
Has it smth to do with the dataview i use?
code snippet:
<asp:datagrid id="DataGrid1" EnableViewState="True" runat="server"
AutoGenerateColumns="False" OnEditCommand="DoItemEdit"
OnUpdateCommand="DoItemUpdate" OnDeleteCommand="DoItemDelete"
OnCancelCommand="DoItemCancel" OnItemCommand="ShowInfo">
<Columns>
<asp:BoundColumn Visible="False" DataField="movieID"
HeaderText="movieID"></asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="userID"
HeaderText="userID"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Titel">
<ItemTemplate>
<asp:Label ID="lblmovieName" Text='<%#
DataBinder.Eval(Container.DataItem, "movieName") %>' Runat="server"/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtmovieName" Width="300" Text='<%
DataBinder.Eval(Container.DataItem, "movieName") %>' Runat="server"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Aantal CD's">
<ItemTemplate>
<asp:Label Text='<%# DataBinder.Eval(Container.DataItem,
"movieAantalCD") %>' Runat="server" ID="lblmovieAantalCD"/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtmovieAantalCD" Width="25" Text='<%
DataBinder.Eval(Container.DataItem, "movieAantalCD") %>' Runat="server"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="FrameRate">
<ItemTemplate>
<asp:Label Text='<%# DataBinder.Eval(Container.DataItem,
"movieFrameRate") %>' Runat="server" ID="lblmovieFrameRate"/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtmovieFrameRate" Width="70" Text='<%
DataBinder.Eval(Container.DataItem, "movieFrameRate") %>' Runat="server"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Codec">
<ItemTemplate>
<asp:Label Text='<%# DataBinder.Eval(Container.DataItem,
"movieCodec") %>' Runat="server" ID="lblmovieCodec"/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtmovieCodec" Width="150" Text='<%
DataBinder.Eval(Container.DataItem, "movieCodec") %>' Runat="server"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button Text="Info!" id="btnInfo" CommandName="Info"
Runat="server"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update"
HeaderText="Bewerk" CancelText="Cancel"
EditText="Bewerk"></asp:EditCommandColumn>
<asp:ButtonColumn Visible="False" Text="Delete"
ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid>
CODE BEHIND:
Protected Sub BindGrid()
Dim mySelection As String = Request.QueryString("Letter")
Dim findString As String
If (mySelection = "0..9") Then
findString = "movieName LIKE '0*'"
findString += "OR movieName LIKE '2*'"
findString += "OR movieName LIKE '3*'"
findString += "OR movieName LIKE '4*'"
findString += "OR movieName LIKE '5*'"
findString += "OR movieName LIKE '6*'"
findString += "OR movieName LIKE '7*'"
findString += "OR movieName LIKE '8*'"
findString += "OR movieName LIKE '9*'"
Else
findString = "movieName LIKE '" & mySelection & "*'"
End If
MyDS1 = CType(Session("myDataSet"), DataSet)
Dim MyDataTable As DataTable = MyDS1.Tables("FilmTabel")
Dim objDataView As New DataView(MyDataTable)
objDataView.RowFilter = findString
DataGrid1.DataSource = objDataView
DataGrid1.DataBind()
DataGrid1.Visible = True
End Sub
Public Sub ShowInfo(ByVal objS As System.Object, ByVal objArgs As
DataGridCommandEventArgs)
If objArgs.CommandSource.commandname = "Info" Then
Dim myName As String = objArgs.Item.Cells(2).Text()
TextBox1.Text = "test" 'myName
Response.Redirect("../webFrom2.aspx?movie=" & myName)
End If
End Sub
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
'stop in session om round-trip te vermijden bij iedere postback
BindList()
If Session("init") Then
SqlSelectCommand1.Parameters("@userID").Value = "1"
'maak een tabel aan om in de dataSet te steken
Dim myTable As DataTable = New DataTable("FilmTabel")
'voeg toe aan dataset
MyDS1.Tables.Add(myTable)
'Vull de dataTable met waarden uit DataBase
SqlDataAdapter1.Fill(myTable)
Session("myDataSet") = MyDS1
DataGrid1.Visible = False
Session("init") = False
Else
BindGrid()
End If
End Sub
Sub DoItemEdit(ByVal objSource As Object, ByVal objARgs As
DataGridCommandEventArgs)
'note: eerst datagrid binden, dan pas de index meegeven, omdat anders de
'edit uitgevoerd wordt, maar de gegevens nog niet aanwezig zijn in de dataset
DataGrid1.EditItemIndex = -1
BindGrid()
DataGrid1.EditItemIndex = objARgs.Item.ItemIndex
DataGrid1.Columns(7).Visible = True
End Sub
Sub DoItemUpdate(ByVal objSource As Object, ByVal objARgs As
DataGridCommandEventArgs)
DataGrid1.EditItemIndex = -1
BindGrid()
DataGrid1.Columns(7).Visible = False
End Sub
Sub DoItemDelete(ByVal objSource As Object, ByVal objARgs As
DataGridCommandEventArgs)
DataGrid1.EditItemIndex = -1
B indGrid()
DataGrid1.EditItemIndex = objARgs.Item.ItemIndex
DataGrid1.Columns(7).Visible = False
End Sub
Sub DoItemCancel(ByVal objSource As Object, ByVal objARgs As
DataGridCommandEventArgs)
DataGrid1.EditItemIndex = -1
BindGrid()
DataGrid1.Columns(7).Visible = False
End Sub