_Esam
asked on
How to set datalist datasouce/event properties inside a repeater.(VB.NET)
Hi,
I have a datalist inside a repeater.
I was able to add the datasource for this repeater..
But I also need to LinkButton the datalist items,,and handle their events..
I can implement these if the datalist was just by itself..
My problem is now it is nested within a repeater..
I need to know how exactly I do that..
This is what I would like to do:
<asp:repeater id="TermDetails" Runat="server" OnItemDataBound="GetTermRe latedInfo" >
<ItemTemplate>
<tr>
<td colspan="2" align="left">See Also
<asp:DataList ID="RelatedTerms" Runat="server">
<ItemTemplate>
'<%#Container.DataItem("GR _Type")%>'
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</ItemTemplate>
</asp:repeater>
For simplicity, I did not include the details of the main repeater.
How can I set datasource, LinkButtion the datalist items, and handle events for these datalist items.
Please let me know.
Thx.
_Esam
I have a datalist inside a repeater.
I was able to add the datasource for this repeater..
But I also need to LinkButton the datalist items,,and handle their events..
I can implement these if the datalist was just by itself..
My problem is now it is nested within a repeater..
I need to know how exactly I do that..
This is what I would like to do:
<asp:repeater id="TermDetails" Runat="server" OnItemDataBound="GetTermRe
<ItemTemplate>
<tr>
<td colspan="2" align="left">See Also
<asp:DataList ID="RelatedTerms" Runat="server">
<ItemTemplate>
'<%#Container.DataItem("GR
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</ItemTemplate>
</asp:repeater>
For simplicity, I did not include the details of the main repeater.
How can I set datasource, LinkButtion the datalist items, and handle events for these datalist items.
Please let me know.
Thx.
_Esam
I have been beaten to the punch... This is what I was going to suggest:
Private Sub DataGrid1_ItemCreated(ByVa l sender As Object, ByVal e As System.Web.UI.WebControls. DataGridIt emEventArg s) Handles DataGrid1.ItemCreated
Dim objRepeater As Repeater
objRepeater = CType(e.Item.FindControl(" myrepeater name"), Repeater)
With objRepeater
.DataSource = mydatasource
.DataBind()
End With
End Sub
Private Sub DataGrid1_ItemCreated(ByVa
Dim objRepeater As Repeater
objRepeater = CType(e.Item.FindControl("
With objRepeater
.DataSource = mydatasource
.DataBind()
End With
End Sub
ASKER
Hi,
Sorry there were some errors while copying, pasting...
For the inner datalist, I would like to have something like this:
The text property set to the GT_Term (string field from G_Term table)
But the CommandName set to the GT_ID (ID for the GT_Term in G_Term table)
And when the LinkButtoned datalist is clicked, I would like the send a session variable for
this GT_ID.
Per, B..M's suggestion, I actually don't need to find the control (datalist) inside this
repeater?
Thx.
_Esam
Sorry there were some errors while copying, pasting...
For the inner datalist, I would like to have something like this:
The text property set to the GT_Term (string field from G_Term table)
But the CommandName set to the GT_ID (ID for the GT_Term in G_Term table)
And when the LinkButtoned datalist is clicked, I would like the send a session variable for
this GT_ID.
Per, B..M's suggestion, I actually don't need to find the control (datalist) inside this
repeater?
Thx.
_Esam
_Esam ,
no you don't have to search for it the event is set for the datalist
you have to check, just be sure, if the declaration of the event should be public
because(may be) otherwise the asp.net will not find it
B..M
no you don't have to search for it the event is set for the datalist
you have to check, just be sure, if the declaration of the event should be public
because(may be) otherwise the asp.net will not find it
B..M
ASKER
This is what I was doing earlier,
Now I need to put thid datalist (another one like this) inside the repeater and pretty much do the same things as I did with this example. Hope I am clear.
<asp:datalist id="TermList" runat="server" OnItemCommand="GetTerms">
<ItemTemplate>
<asp:LinkButton id="TermType" Runat="server" Text= '<%
#Container.DataItem("GT_Te rm")%>' CommandName= '<%
#Container.DataItem("GT_ID ")%>' />
</ItemTemplate>
</asp:datalist>
</tr>
Sub GetTerms(ByVal Src As Object, ByVal Args As DataListCommandEventArgs)
Session("Term_Value") = Args.CommandName
Response.Redirect("VUI_G_T erms.aspx" )
End Sub
_Esam
Now I need to put thid datalist (another one like this) inside the repeater and pretty much do the same things as I did with this example. Hope I am clear.
<asp:datalist id="TermList" runat="server" OnItemCommand="GetTerms">
<ItemTemplate>
<asp:LinkButton id="TermType" Runat="server" Text= '<%
#Container.DataItem("GT_Te
#Container.DataItem("GT_ID
</ItemTemplate>
</asp:datalist>
</tr>
Sub GetTerms(ByVal Src As Object, ByVal Args As DataListCommandEventArgs)
Session("Term_Value") = Args.CommandName
Response.Redirect("VUI_G_T
End Sub
_Esam
ASKER
Hi B.M.
I'm clear with event handling for the inner datalist within the repeater now.
How do I set the datasource for this inner datalist?
_Esam
I'm clear with event handling for the inner datalist within the repeater now.
How do I set the datasource for this inner datalist?
_Esam
_Esam,
you have to use the OnItemDataBound event of the repeater
and in it
if e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingIt em Then
Dim datalistSearched as DataList = Ctype(e.Item.FindControl(" your data list control", DataList)
datalistSearched.Datasourc e = '
datalistSearched.DataBind( )
End if
B..M
you have to use the OnItemDataBound event of the repeater
and in it
if e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingIt
Dim datalistSearched as DataList = Ctype(e.Item.FindControl("
datalistSearched.Datasourc
datalistSearched.DataBind(
End if
B..M
ASKER
Thanks B..M
Let me try it real quick and get back to you...
_Esam
Let me try it real quick and get back to you...
_Esam
ASKER
Hi,
This is what I tried to do..
Maybe there are some sort of errors..
Dim tv As String
tv = Session("Term_Value").ToSt ring
Dim cns As New OleDbConnection
Dim ss As String = Server.MapPath("ADVOICE.md b")
cns.ConnectionString = "provider =Microsoft.Jet.OLEDB.4.0; data source = " + ss
cns.Open()
Dim das As New OleDbDataAdapter("SELECT G_Term.*, G_Related_Terms.GT_ID, G_Related_Terms.GT_ID_Othe r FROM G_Term INNER JOIN G_Related_Terms ON G_Term.GT_ID=G_Related_Ter ms.GT_ID_O ther " & _
"WHERE G_Related_Terms.GT_ID =" & tv, cns)
Dim dss As New DataSet
das.Fill(dss, "G_Term")
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingIt em Then
Dim TermRList as DataList = Ctype(e.Item.FindControl(" RelatedTer ms", DataList) 'it expects a comma here?
TermRList.DataSource = dss
TermRList.DataMember = "G_Term"
TermRList.DataBind()
End If
cns.Close()
It complaint that all the TermRList are not declared, and also expects a ' around Datalist?
_Esam
This is what I tried to do..
Maybe there are some sort of errors..
Dim tv As String
tv = Session("Term_Value").ToSt
Dim cns As New OleDbConnection
Dim ss As String = Server.MapPath("ADVOICE.md
cns.ConnectionString = "provider =Microsoft.Jet.OLEDB.4.0; data source = " + ss
cns.Open()
Dim das As New OleDbDataAdapter("SELECT G_Term.*, G_Related_Terms.GT_ID, G_Related_Terms.GT_ID_Othe
"WHERE G_Related_Terms.GT_ID =" & tv, cns)
Dim dss As New DataSet
das.Fill(dss, "G_Term")
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingIt
Dim TermRList as DataList = Ctype(e.Item.FindControl("
TermRList.DataSource = dss
TermRList.DataMember = "G_Term"
TermRList.DataBind()
End If
cns.Close()
It complaint that all the TermRList are not declared, and also expects a ' around Datalist?
_Esam
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get an error as:
GT_ID is neither a DataColumn nor a DataRelation for table G_Term.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: GT_ID is neither a DataColumn nor a DataRelation for table G_Term.
Source Error:
Line 104: <asp:DataList ID="RelatedTerms" Runat="server">
Line 105: <ItemTemplate>
Line 106: <asp:LinkButton id="TermType" Runat="server" Text= '<%
#Container.DataItem("GT_Te rm")%>' CommandName= '<%#Container.DataItem
("GT_ID")%>' /><BR>
Line 107: </ItemTemplate>
Line 108: </asp:Datalist>
Source File: c:\inetpub\wwwroot\ADVOICE _Final\VUI _G_Terms.a spx Line: 106
Is it because, I searched the G_Related_terms tables, but bounded the values from G_Term?
U can see that from the other post where I made the query.
_Esam
GT_ID is neither a DataColumn nor a DataRelation for table G_Term.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: GT_ID is neither a DataColumn nor a DataRelation for table G_Term.
Source Error:
Line 104: <asp:DataList ID="RelatedTerms" Runat="server">
Line 105: <ItemTemplate>
Line 106: <asp:LinkButton id="TermType" Runat="server" Text= '<%
#Container.DataItem("GT_Te
("GT_ID")%>' /><BR>
Line 107: </ItemTemplate>
Line 108: </asp:Datalist>
Source File: c:\inetpub\wwwroot\ADVOICE
Is it because, I searched the G_Related_terms tables, but bounded the values from G_Term?
U can see that from the other post where I made the query.
_Esam
ASKER
Please note that my parent repeater is also using some fields from G_Term.
I also need to include some related terms, with this inner datalist, from the same G_Term
table comparing with another tablse as I did in the query..
_Esam
I also need to include some related terms, with this inner datalist, from the same G_Term
table comparing with another tablse as I did in the query..
_Esam
_Esam,
so you mean that you've bound the LinkButton to values from the master control's ( repeater ) datasource, not from the datalist's datasource, correct ?
if yes, you have to use DataBinder.Eval
if you mixed - some of the values are got from the master - for them you have to use DataBinder.Eval(Container. DataItem, "column name")
for the others, because of the nested controls, you have to create ItemDataBound event of the datalist ( like the ItemCommand ), before that ( int the itemCommand event ) to store the datalist datasource in a variable, so in the ItemDataBound of the datalist control you can get this stored datasource, find the control you wanted to bind by FindControl method and set it's value to a current value
B..M
so you mean that you've bound the LinkButton to values from the master control's ( repeater ) datasource, not from the datalist's datasource, correct ?
if yes, you have to use DataBinder.Eval
if you mixed - some of the values are got from the master - for them you have to use DataBinder.Eval(Container.
for the others, because of the nested controls, you have to create ItemDataBound event of the datalist ( like the ItemCommand ), before that ( int the itemCommand event ) to store the datalist datasource in a variable, so in the ItemDataBound of the datalist control you can get this stored datasource, find the control you wanted to bind by FindControl method and set it's value to a current value
B..M
ASKER
Well,
I did use the datalist datasource for the LinkButton..
What I meant is that this datalist datasource get the values from the same table as
does the master repeater datasource (I set up the repeater datasource from this G_Term table, it worked before..., problem is with the inner datalist) That shouldn't be a problem, I think, if otherwise.
Thus when I tried the Databinder,,,there were some errors as expected...
_Esam
I did use the datalist datasource for the LinkButton..
What I meant is that this datalist datasource get the values from the same table as
does the master repeater datasource (I set up the repeater datasource from this G_Term table, it worked before..., problem is with the inner datalist) That shouldn't be a problem, I think, if otherwise.
Thus when I tried the Databinder,,,there were some errors as expected...
_Esam
_Esam,
the fact that you use one table is the easy part - when you create the datasource for datalist control , you've already have the datasource for it
what errors actually do you receive ?
B..M
the fact that you use one table is the easy part - when you create the datasource for datalist control , you've already have the datasource for it
what errors actually do you receive ?
B..M
ASKER
Hi B..M.
This is what happens..
If I remove the GT_ID (CommandName) from this:
<asp:LinkButton id="TermType" Runat="server" Text= '<%#Container.DataItem("GT _Term")%>' CommandName= '<%#Container.DataItem("GT _ID")%>' />
I works, just shows me the related terms list with linkbuttons...
I also need to add the CommandName..
_Esam
This is what happens..
If I remove the GT_ID (CommandName) from this:
<asp:LinkButton id="TermType" Runat="server" Text= '<%#Container.DataItem("GT
I works, just shows me the related terms list with linkbuttons...
I also need to add the CommandName..
_Esam
ASKER
This is the error I get if I include GT_ID for my CommandName for the datalist items
I think something else need to be done here..
GT_ID is neither a DataColumn nor a DataRelation for table G_Term.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: GT_ID is neither a DataColumn nor a DataRelation for table G_Term.
Source Error:
Line 104: <asp:DataList ID="RelatedTerms" Runat="server">
Line 105: <ItemTemplate>
Line 106: <asp:LinkButton id="TermType" Runat="server" Text= '<%#Container.DataItem("GT _Term")%>' CommandName= '<%#Container.DataItem("GT _ID")%>'/>
Line 107: </ItemTemplate>
Line 108: </asp:DataList>
Source File: c:\inetpub\wwwroot\ADVOICE _Final\VUI _G_Terms.a spx Line: 106
_Esam
I think something else need to be done here..
GT_ID is neither a DataColumn nor a DataRelation for table G_Term.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: GT_ID is neither a DataColumn nor a DataRelation for table G_Term.
Source Error:
Line 104: <asp:DataList ID="RelatedTerms" Runat="server">
Line 105: <ItemTemplate>
Line 106: <asp:LinkButton id="TermType" Runat="server" Text= '<%#Container.DataItem("GT
Line 107: </ItemTemplate>
Line 108: </asp:DataList>
Source File: c:\inetpub\wwwroot\ADVOICE
_Esam
ASKER
To be clear,,
I haven't created any datalist event item handler yet....this should not matter now..
since at this moment I am not doing anything with the datalist items...i am taking a step at a time..
_Esam
I haven't created any datalist event item handler yet....this should not matter now..
since at this moment I am not doing anything with the datalist items...i am taking a step at a time..
_Esam
just use this
<asp:repeater id="TermDetails" Runat="server" OnItemDataBound="GetTermRe
<ItemTemplate>
<tr>
<td colspan="2" align="left">See Also
<asp:DataList ID="RelatedTerms" Runat="server" OnItemCommand="DataListIte
<ItemTemplate>
'<%#Container.DataItem("GR
<asp:LinkButton id="SelectButton"
Text="Select"
CommandName="Select"
runat="server"/>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</ItemTemplate>
</asp:repeater>
vb.net
Sub DataListItem_Command(sende
if e.CommandName = "Select" Then
'do what you want with your link button
End if
End Sub
c#
void DataListItem_Command(Objec
{
if ( e.CommandName == "Select" )
{
//do what you want with your link button
}
}
B..M