I have two stored procedures, one returns the user name and a few other bits of information. the second stored procedure retrives the progress messages about the user. Some users will have progress messages and others my not.
I started by using a listview to display the first stored procedure which gives me the idname, first name and last name, but I want to use a db reader or some other way to use the second stored procedure to show the progress inforamtion associated with the
user id name. How can I do this?
I want the layout to be something like this:
idname first name last name
234 Bob smith
prog message date title
555 1/12/12 moved out of town
________________________________________________________
456 Jimmy Jones
_______________________________________________________
898 Dave Lewis
prog message date title
222 2/22/10 Needs updated
676 5/15/08 completed
You could nest a ListView (or GridView) in the ListView Item. Don't bind it in .aspx.
In the ItemDataBound handler of the ListView check Type. If it is a DataItem, find the GridView in it using FindControl.
Get the data you need to feed the second stored procedure from the DataItem of the Item, using DataBinder.Eval.
Then you can get a reader for the second stored procedure and set it as DataSource on the GridView. Call DataBind on the GridView, and it should work.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Okay I have my outside listview bound to a data source and using onitemdatabound to find the countrol and value of one of the fileds so I can compare it with the inner nested listview but I can't seem to use find control with the outer listview itemdatabound
to get the inner listview control.
ListView may also call ItemDataBound for Items other than DataItem. See if you can check the Type and only look for the nested ListView when the Item is a DataItem.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Sorry to trouble you superguppie. I thought I'd show you what I have and you perhaps you can guide me to the right direction. My outside Listview is bound to a datasouirce works fine. The inside listview I thought I was going to bind to a datasource but
I might use the db reader. Not sure any suggestions? What I need to do is match the outside listview trackno field to see if it matches the inner trackno hiddenfield, if it does then show the inside listview.
Here is my listview and Itemdatabound event so far:
Your direction is right. What you need to do is you also need to pass the value to the "inOp" selectparameter for the inner SqlDataSource and set the selectcommand (this can be set in the markup I think). Maybe the value of "inOp" parameter is from the parent
ListView, so you can access this value from the e.Item in the event, too.
You could do it with a reader in code-behind. However, you could also do it without any code-behind. Each has its ups and downs.
Either way, Qin Dian Tang is right that you have to pass a value from the DataItem of the Item it is in. I am guessting that is inOp.
To do it in .aspx, without extra code:
Set the name of the SP on the SelectCommand in .aspx.
If the value to pass isn't in a Control already, put a HiddenField next to the SqlDataSource and bind its Value to the field.
Put a ControlParameter in the SelectParameters. (If the field to pass is to go to Parameter inOp, just change that to ControlParameter.)
Have the ControlParameter pick up the value from the Control that holds it.
If you want to do it in code-behind, just ask.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Marked as answer by rsvore on Apr 05, 2012 08:22 PM
Thanks again, I getting lost now. The inop value is to select the 7th stored procedure in my inner listview stored procedure to run that particullar select statement. Then I also pass the scn number to the inner stored procedure seems like I need to also
get the trackno from the outer listview but just not getting it. (Took my dumb pills this morning) I'm so close but it's not clicking for me.
You already have trackno in a Label. You can use a ControlParameter to get it from that Label and pass it to the stored procedure.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
rsvore
Member
324 Points
286 Posts
Best way to handle two datasources and binding them
Mar 30, 2012 02:51 PM|LINK
I have two stored procedures, one returns the user name and a few other bits of information. the second stored procedure retrives the progress messages about the user. Some users will have progress messages and others my not.
I started by using a listview to display the first stored procedure which gives me the idname, first name and last name, but I want to use a db reader or some other way to use the second stored procedure to show the progress inforamtion associated with the user id name. How can I do this?
I want the layout to be something like this:
idname first name last name
234 Bob smith
prog message date title
555 1/12/12 moved out of town
________________________________________________________
456 Jimmy Jones
_______________________________________________________
898 Dave Lewis
prog message date title
222 2/22/10 Needs updated
676 5/15/08 completed
superguppie
All-Star
48225 Points
8679 Posts
Re: Best way to handle two datasources and binding them
Mar 30, 2012 03:03 PM|LINK
You could nest a ListView (or GridView) in the ListView Item. Don't bind it in .aspx.
In the ItemDataBound handler of the ListView check Type. If it is a DataItem, find the GridView in it using FindControl.
Get the data you need to feed the second stored procedure from the DataItem of the Item, using DataBinder.Eval.
Then you can get a reader for the second stored procedure and set it as DataSource on the GridView. Call DataBind on the GridView, and it should work.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
rsvore
Member
324 Points
286 Posts
Re: Best way to handle two datasources and binding them
Mar 30, 2012 03:32 PM|LINK
Thanks I'll give it a try.
rsvore
Member
324 Points
286 Posts
Re: Best way to handle two datasources and binding them
Apr 01, 2012 01:30 PM|LINK
Okay I have my outside listview bound to a data source and using onitemdatabound to find the countrol and value of one of the fileds so I can compare it with the inner nested listview but I can't seem to use find control with the outer listview itemdatabound to get the inner listview control.
superguppie
All-Star
48225 Points
8679 Posts
Re: Best way to handle two datasources and binding them
Apr 02, 2012 11:52 AM|LINK
ListView may also call ItemDataBound for Items other than DataItem. See if you can check the Type and only look for the nested ListView when the Item is a DataItem.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
rsvore
Member
324 Points
286 Posts
Re: Best way to handle two datasources and binding them
Apr 02, 2012 11:08 PM|LINK
Sorry to trouble you superguppie. I thought I'd show you what I have and you perhaps you can guide me to the right direction. My outside Listview is bound to a datasouirce works fine. The inside listview I thought I was going to bind to a datasource but I might use the db reader. Not sure any suggestions? What I need to do is match the outside listview trackno field to see if it matches the inner trackno hiddenfield, if it does then show the inside listview.
Here is my listview and Itemdatabound event so far:
<asp:ListView ID="ListViewOutter" runat="server" DataSourceID="SqlDataSourceOutter" OnItemDataBound="ListViewOutter_ItemDataBound" > <LayoutTemplate> <table ID="Table1" runat="server" width="100%"> <tr ID="Tr1" runat="server"> <td ID="Td1" runat="server"> <table ID="itemPlaceholderContainer" runat="server" border="0" width="100%"> <tr ID="Tr2" runat="server"> <td id="Td23" runat="server" style="text-align:Left; width: 125px; border-style: none none; vertical-align:Bottom;"> </td> <td ID="Th1" runat="server" style="text-align:Left; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> SFX</td> <td ID="Th2" runat="server" style="text-align:Left; width: 75px; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> Status</td> <td ID="Th3" runat="server" style="text-align:Left; width: 58px; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> MASL</td> <td ID="Td10" runat="server" style="text-align:Left; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> Course</td> <td ID="Td11" runat="server" style="text-align:Left; width: 70px; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> Rpt Dt</td> <td ID="Td12" runat="server" style="text-align:Left; width: 70px; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> Start Dt</td> <td ID="Td18" runat="server" style="text-align:Left; width: 70px; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> End Dt</td> <td ID="Td19" runat="server" style="text-align:Left; width: 48px; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> Loc</td> <td ID="Td20" runat="server" style="text-align:Left; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> School</td> <td ID="Td21" runat="server" style="text-align:Left; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> Req CL</td> <td ID="Td22" runat="server" style="text-align:Left; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> Req ECL</td> </tr> <tr ID="itemPlaceholder" runat="server"> </tr> </table> </td> </tr> <tr ID="Tr3" runat="server"> <td ID="Td2" runat="server" style=""> </td> </tr> </table> </LayoutTemplate> <EmptyDataTemplate> <table ID="Table1" runat="server" style=""> <tr> <td> No data was returned.</td> </tr> </table> </EmptyDataTemplate> <ItemTemplate> <tr> <td style="text-align:Left; vertical-align:top;"> <asp:Label ID="lbltrackno" runat="server" Text='<%# Eval("trackno") %>' /> </td> </tr> <tr> <td style="text-align:Left;vertical-align:top;"> </td> <td style="text-align:Left;vertical-align:top;"> <asp:Label ID="Label18" runat="server" Text='<%# Eval("wcn_suf") %>' /> </td> <td style="text-align:Left; vertical-align:top;"> <asp:Label ID="Label19" runat="server" Text='<%# Eval("Title_nm") %>' /> </td> <td style="text-align:Left; vertical-align:top;"> <asp:Label ID="lblisu_dt" runat="server" Text='<%# Eval("masl_id") %>' /> </td> <td style="text-align:Left; vertical-align:top;"> <asp:Label ID="Label20" runat="server" Text='<%# Eval("title") %>' /> </td> <td style="text-align:Left; vertical-align:top;"> <asp:Label ID="lblisu_place" runat="server" Text='<%# Eval("rpt_dt","{0:dd-MMM-y}") %>' /> </td> <td style="text-align:Left; vertical-align:top;"> <asp:Label ID="Label21" runat="server" Text='<%# Eval("start_dt","{0:dd-MMM-y}") %>' /> </td> <td style="text-align:Left; vertical-align:top;"> <asp:Label ID="Label22" runat="server" Text='<%# Eval("end_dt","{0:dd-MMM-y}") %>' /> </td> <td style="text-align:Left; vertical-align:top;"> <asp:Label ID="Label14" runat="server" Text='<%# Eval("loc") %>' /> </td> <td style="text-align:Left; vertical-align:top;"> <asp:Label ID="Label15" runat="server" Text='<%# Eval("schname") %>' /> </td> <td style="text-align:Left; vertical-align:top;"> <asp:Label ID="Label16" runat="server" Text='<%# Eval("cl") %>' /> </td> <td style="text-align:Left; vertical-align:top;"> <asp:Label ID="Label23" runat="server" Text='<%# Eval("ecl") %>' /> </td> </tr> <tr> <td style="text-align:Left;vertical-align:top;"> </td> <td rowspan="11"> <asp:ListView ID="ListViewInner" runat="server" DataSourceID="SubCategory"> <LayoutTemplate> <table runat="server" id="table2"> <tr runat="server" id="itemPlaceHolder"> <td ID="Td22" runat="server" style="text-align:Left; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> Eff Dt.</td> <td ID="Td25" runat="server" style="text-align:Left; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> Begin Dt.</td> <td ID="Td26" runat="server" style="text-align:Left; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> End Dt.</td> <td ID="Td27" runat="server" style="text-align:Left; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> Progress Message</td> <td ID="Td28" runat="server" style="text-align:Left; border-style: none none solid none; border-bottom-width: 1px; border-bottom-color: #000000; vertical-align:Bottom;"> Comment</td> </tr> </table> </LayoutTemplate> <ItemTemplate> <tr id="inner1" runat="server"> <td id="inner2" runat="server" align="left"> <asp:Label ID="Labeleff_dt" runat="server" Text='<%#Eval("eff_dt","{0:dd-MMM-y}")%>' /> </td> <td id="inner3" runat="server" align="left"> <asp:Label ID="Label25" runat="server" Text='<%#Eval("prior_dt","{0:dd-MMM-y}")%>'></asp:Label> </td> <td id="inner4" runat="server" align="left"> <asp:Label ID="Label26" runat="server" Text='<%#Eval("last_dt","{0:dd-MMM-y}")%>'></asp:Label> </td> <td id="inner5" runat="server" align="left"> <asp:Label ID="Label27" runat="server" Text='<%#Eval("comment")%>'></asp:Label> </td> <td id="inner6" runat="server" align="left"> <asp:Label ID="Label28" runat="server" Text='<%#Eval("pub_cmnt")%>'></asp:Label> </td> <td id="inner7" runat="server" align="left"> <asp:HiddenField ID="hfTrackNo" runat="server" value='<%#Eval("trackno")%>'/> </td> </tr> </ItemTemplate> </asp:ListView> <asp:SqlDataSource ID="SubCategory" runat="server" ConnectionString="connectionstring" SelectCommand="" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:Parameter DefaultValue="7" Name="inOp" Type="Int32" /> <asp:QueryStringParameter DefaultValue="AT006061" Name="scn" QueryStringField="scn" Type="String" /> </SelectParameters> </asp:SqlDataSource> </td> </tr> </ItemTemplate> </asp:ListView> <asp:SqlDataSource ID="SqlDataSourceOutter" runat="server" ConnectionString="connectionstring" SelectCommand="usp_scn_report" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:Parameter DefaultValue="6" Name="inOp" Type="Int32" /> <asp:QueryStringParameter DefaultValue="AT006061" Name="scn" QueryStringField="scn" Type="String" /> </SelectParameters> </asp:SqlDataSource> Protected Sub ListViewOutter_ItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs) ' hide extra trackno listed in Outter Listview If e.Item.ItemType = ListViewItemType.DataItem Then Dim Labellbltrackno As Label = e.Item.FindControl("lbltrackno") Dim strval As String = CType(Labellbltrackno, Label).Text Dim gvtitle As String = ViewState("trackno") If gvtitle = strval Then Labellbltrackno.Visible = False Labellbltrackno.Text = String.Empty Else gvtitle = strval ViewState("trackno") = gvtitle Labellbltrackno.Visible = True End If End If Dim sqlds As SqlDataSource = e.Item.FindControl("SubCategory") 'sqlds.SelectCommand = "usp_scn_report" Dim lblTrackno As Label = e.Item.FindControl("lbltrackno") Dim HiddenFtrackno As HiddenField = e.Item.FindControl("hfTrackNo") Dim Labeleff_dt As Label = e.Item.FindControl("Labeleff_dt") Dim showListViewInner As ListView = e.Item.FindControl("ListViewInner") 'If lblTrackno.Text = HiddenFtrackno.Value Then ' showListViewInner.Visible = True 'Else ' showListViewInner.Visible = False 'End If End SubQin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Best way to handle two datasources and binding them
Apr 03, 2012 03:52 AM|LINK
Hi,
Your direction is right. What you need to do is you also need to pass the value to the "inOp" selectparameter for the inner SqlDataSource and set the selectcommand (this can be set in the markup I think). Maybe the value of "inOp" parameter is from the parent ListView, so you can access this value from the e.Item in the event, too.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
superguppie
All-Star
48225 Points
8679 Posts
Re: Best way to handle two datasources and binding them
Apr 03, 2012 08:44 AM|LINK
You could do it with a reader in code-behind. However, you could also do it without any code-behind. Each has its ups and downs.
Either way, Qin Dian Tang is right that you have to pass a value from the DataItem of the Item it is in. I am guessting that is inOp.
To do it in .aspx, without extra code:
Set the name of the SP on the SelectCommand in .aspx.
If the value to pass isn't in a Control already, put a HiddenField next to the SqlDataSource and bind its Value to the field.
Put a ControlParameter in the SelectParameters. (If the field to pass is to go to Parameter inOp, just change that to ControlParameter.)
Have the ControlParameter pick up the value from the Control that holds it.
If you want to do it in code-behind, just ask.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
rsvore
Member
324 Points
286 Posts
Re: Best way to handle two datasources and binding them
Apr 03, 2012 02:14 PM|LINK
Thanks again, I getting lost now. The inop value is to select the 7th stored procedure in my inner listview stored procedure to run that particullar select statement. Then I also pass the scn number to the inner stored procedure seems like I need to also get the trackno from the outer listview but just not getting it. (Took my dumb pills this morning) I'm so close but it's not clicking for me.
superguppie
All-Star
48225 Points
8679 Posts
Re: Best way to handle two datasources and binding them
Apr 03, 2012 02:25 PM|LINK
You already have trackno in a Label. You can use a ControlParameter to get it from that Label and pass it to the stored procedure.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.