 |
| ASP.NET 4.5 General Discussion For ASP.NET 4.5 discussions not relating to a specific Wrox book |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 4.5 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 16th, 2014, 01:10 PM
|
|
Registered User
|
|
Join Date: May 2014
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Finding control in Item Template
Frustration level - high
How do you get the data that comes back from a select statement insid a list control. I can get controls in insert and update templates. But how on earth do you find a control in the Item template? And if that is not possible, how can you get that returned data of a specific field?
Anybody?
Reason is, I want to take that data that is returned from an SQL query (inside a ListView control) and use that to drive a Grid View.
Last edited by Bruce Weber; May 16th, 2014 at 02:43 PM..
|
|

May 16th, 2014, 05:26 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
I am not sure I understand what you're asking. What are you trying to accomplish? Can you elaborate?
Imar
|
|

May 16th, 2014, 06:31 PM
|
|
Registered User
|
|
Join Date: May 2014
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Imar,
First I am new to web programming, but not to programming, so bear with me a bit. I am trying to build a web site for my organization. One thing I am trying to do is build a page that has a dropdown list linked to a listview to show instructions. That info stays static for the duration. Below that I have another listview that displays a mailing address. I want to incrementally walk through the addresses. Below that I want to have a Grid Control that displays a list of people with related info that is tied to the address.
The problem comes from trying to access the various controls from within the ItemTemplate. I can easily find the controls within the Insert and Update templates using FindControl, but I can't seem to figure out how to find the bound controls within the ItemTemplate.
It is frustrating to figure out how to do a work-around when I shouldn't need to... or... Help, Please
By the way, I like your beginning ASP.Nety 4.5, and it is really helpful, even though I'm still on XP. I am reluctant to changet to Windows 7 or 8 because I don't want to spend$$ to upgrand my Delphi (Code Gear) software.
Last edited by Bruce Weber; May 16th, 2014 at 06:38 PM..
|
|

May 16th, 2014, 06:34 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Can you post the relevant code along with a description about what you expect to access from where?
Imar
|
|

May 16th, 2014, 06:50 PM
|
|
Registered User
|
|
Join Date: May 2014
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Code:
Program<asp:DropDownList ID="ProgramDropDownList" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSourceProgams"
DataTextField="Description" DataValueField="Id"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceProgams" runat="server"
ConnectionString="<%$ ConnectionStrings:GOPConnectionString %>"
SelectCommand="GetCallPrograms" SelectCommandType="StoredProcedure">
</asp:SqlDataSource><br />
<asp:ListView ID="ScriptListView" runat="server"
DataSourceID="SqlDataSourceCallScripts">
<ItemTemplate>
<td runat="server" style="">
<table>
<tr>
<td align="center">LiveScript</td>
<td align="center">Answering Machine Script</td>
</tr>
<tr>
<td>
<asp:TextBox ID="LiveScriptTextBox" runat="server"
ReadOnly="true"
Width="425"
Height="150"
TextMode="MultiLine"
Text='<%# Eval("LiveScript") %>' />
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"
ReadOnly="true"
Width="425"
Height="150"
TextMode="MultiLine"
Text='<%# Eval("AnsweringMachineScript") %>' />
</td>
</tr>
</table>
</td>
</ItemTemplate>
<LayoutTemplate>
<table runat="server" border="0" style="">
<tr ID="itemPlaceholderContainer" runat="server">
<td ID="itemPlaceholder" runat="server">
</td>
</tr>
</table>
<div style="">
</div>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSourceCallScripts" runat="server"
ConnectionString="<%$ ConnectionStrings:GOPConnectionString %>"
SelectCommand="GetProgramCallScripts" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ProgramDropDownList" Name="Id"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<!---------------->
<asp:DropDownList ID="PlaceDropDownList" runat="server"
DataSourceID="SqlDataSourcetest" DataTextField="Place"
DataValueField="Place" ontextchanged="PlaceDropDownList_TextChanged"
ondatabound="PlaceDropDownList_DataBound">
</asp:DropDownList>
<asp:Label ID="PlaceLabel1" runat="server" Text="0"></asp:Label>
<asp:SqlDataSource ID="SqlDataSourcetest" runat="server"
ConnectionString="<%$ ConnectionStrings:GOPConnectionString %>"
SelectCommand="GetCallPlace" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ProgramDropDownList" Name="Program"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ListView ID="AddressListView" runat="server"
DataSourceID="SqlDataSourceCallPlace" onprerender="AddressListView_PreRender">
<ItemTemplate>
<span style="">
Remaining: <asp:Label ID="RemainingLabel" Font-Bold="false" runat="server" Text='<%# Eval("Remaining") %>' />
Address: <asp:Label ID="AddressLabel" runat="server" Font-Bold="false" Text='<%# Eval("Address") %>' />
<br />
<asp:Button ID="Button2" UseSubmitBehavior="true" OnClick="Button2_Click" runat="server" Text="Button2" />
</span>
</ItemTemplate>
<LayoutTemplate>
<div ID="itemPlaceholderContainer" runat="server" style="">
<span runat="server" id="itemPlaceholder" />
</div>
<div style="">
</div>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSourceCallPlace" runat="server"
ConnectionString="<%$ ConnectionStrings:GOPConnectionString %>"
SelectCommand="GetCallPlace2" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="PlaceDropDownList" Name="Place"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:TextBox ID="PlaceTextBox" AutoPostBack="true" runat="server" Text="0"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button1"
onclick="Button1_Click" UseSubmitBehavior="False" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSourcePlaceVoters" >
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True"
SortExpression="Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender"
SortExpression="Gender" />
<asp:BoundField DataField="Age" HeaderText="Age" ReadOnly="True"
SortExpression="Age" />
<asp:BoundField DataField="Party" HeaderText="Party" SortExpression="Party" />
<asp:BoundField DataField="RegDate" HeaderText="RegDate" ReadOnly="True"
SortExpression="RegDate" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="GeneralHistory" HeaderText="GeneralHistory"
SortExpression="GeneralHistory" />
<asp:BoundField DataField="PrimaryHistory" HeaderText="PrimaryHistory"
SortExpression="PrimaryHistory" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourcePlaceVoters" runat="server"
ConnectionString="<%$ ConnectionStrings:GOPConnectionString %>"
SelectCommand="GetPlaceVoters" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="PlaceTextBox" DefaultValue="0" Name="PlaceId"
PropertyName="Text" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
--------------------------------
What you see here is attempts of work arounds.. probably irrelevant at this point
__________________________________________
public partial class PC_Events : System.Web.UI.Page
{
int NextPlace = 0;
int LastPlace = 0;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_Load(object sender, EventArgs e)
{
}
protected void AddressListView_PreRender(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int x = Convert.ToInt32(PlaceTextBox.Text);
x = x + 1;
PlaceTextBox.Text = x.ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
int x = Convert.ToInt32(PlaceLabel1.Text);
x = x + 1;
PlaceLabel1.Text = x.ToString();
}
protected void PlaceDropDownList_TextChanged(object sender, EventArgs e)
{
}
protected void PlaceDropDownList_DataBound(object sender, EventArgs e)
{
PlaceLabel1.Text = PlaceDropDownList.Text;
}
|
|

May 17th, 2014, 07:17 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Did you take a look at the first link I posted? It seems that handling RowDataBound (or maybe RowCreated) would do the trick. Inside of that handler, you need to look at the RowType and see if it's a DataControlRowType.DataRow before you try to access the controls using FindControl.
Hope this helps,
Imar
|
|
 |