如何从sql访问数据并在运行时在datalist中显示 [英] how to access data from sql and show in datalist at runtime
本文介绍了如何从sql访问数据并在运行时在datalist中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我在asp.net页面中使用datalist,它在设计时显示来自SQL DB的数据。
datalist显示那些居住在旁遮普邦的候选人,但现在我想要更多的排序在该数据中,我有一个显示旁遮普州城市的下拉列表,当用户选择一个特定城市时
datalist仅显示该城市候选人。
请帮助
直到我使用此代码
< span class =code-keyword>< div id = dr1 style = width:300px; padding-bottom:1px; height:630px; overflow:scroll >
< asp:UpdatePanel ID < span class =code-keyword> = UpdatePanel3 runat = server >
< ContentTemplate >
< asp:DataList ID = DataList1 runat = server CellPadding = 4 RepeatLayout = 流程 DataSourceID = SqlDataSource1
ForeColor = #333333 宽度 = 300px RepeatColumns = 2 RepeatDirection = 水平 >
< AlternatingItemStyle BackColor = 白色 ForeColor = #284775 / >
< FooterStyle Font-Bold =跨度> < span class =code-keyword> True ForeColor = 白色 BackColor = #5D7B9D / >
< HeaderStyle 字体粗体 < span class =code-keyword> = True ForeColor = 白色 BackColor = #5D7B9D / >
< ItemStyle ForeColor = #333333 BackColor < span class =code-keyword> = #F7F6F3 / >
< ItemTemplate >
< 一跨度> class =' iframe' href = my-business.aspx?nm ='<% #Eval( 名称)%> ' >
< div class = card style = min-height:50px; >
< div class = fl >
< asp:图像 ID = Image2 runat = 服务器 样式 = border:1px solid#C6C6C6;向左飘浮;
身高:50px; border-radius:3px; width:50px; ImageUrl =' <%# AdminGetImage.aspx?id = + Eval( id)%> ' / >
< / div >
< div class = fl style = margin-left:7px;宽度:215px; >
< div >
< asp:标签 ID = Sent_FromLabel 字体 - 大小 = 10px 样式 = text-transform:capitalize;
font-weight:bold; 字体名称 = Verdana ForeColor = #014265 runat = server 文字 =' <% #Eval( 名称)%> ' / >
< / div >
< div >
< div >
< asp:标签 ID = label3 runat = 服务器 字体名称 = Verdana ForeColor = # 014265 字体大小 = 10px
文本 =' <% #Eval( 地址) %> ' / >
< / div >
< div 样式 = margin-top:2px; >
< asp:标签 ID = Label1 字体大小 = 10px 字体 - 姓名 = Verdana ForeColor = #014265
< span class =code-attribute> runat = server 文字 =' <% #Eval( 移动)%> ' / > ,
< asp:Label ID = Label4 字体大小 = 10px 字体名称 = Verdana < span class =code-attribute> ForeColor = #014265
< span class =code-attribute> runat = server 文本 =' <% #Eval( Office)%> ' / >
< / div >
< div >
< asp:标签 ID = Label2 runat = server 文字 =' < span class =code-keyword> <% #Eval( claim_status)%> ' class = 声明 > < / asp:Label >
< / div >
< / div >
< / div >
< div class = clr >
< / div >
< / div < span class =code-keyword>>
< < span class =code-leadattribute> / a >
< / ItemTemplate >
< SelectedItemStyle BackColor = #E2DED6 Font-Bold = True ForeColor = #333333 / >
< / asp:DataList >
< span class =code-keyword>< / ContentTemplate >
< / asp:UpdatePanel >
< / div >
< asp:SqlDataSource ID = SqlDataSource1 runat = server ConnectionString = <% $ ConnectionStrings:MyArea %>
< span class =code-attribute> SelectCommand = Sp_State_candidate SelectCommandType = StoredProcedure >
< SelectParameters >
< asp:QueryStringParameter 名称 = state QueryStringField = id 类型 = 字符串 / >
< / SelectParameters >
< / asp:SqlDataSource >
解决方案
ConnectionStrings:MyArea %> < span class =code-attribute>
< span class =code-attribute> SelectCommand = Sp_State_candidate SelectCommandType = StoredProcedure < span class =code-keyword>>
< SelectParameters >
< asp:QueryStringParameter 名称 = state QueryStringField = < span class =code-keyword> id 类型 = 字符串 / >
< / SelectParameters >
< / asp:SqlDataSource >
< asp:DropDownList ID = DropDownList1 runat = server DataSourceID = SqlDataSource1
DataTextField = city_name DataValueField = city_id AutoPostBack = true BackColor = IndianRed
ForeColor = Snow >
< / asp:DropDownList >
< asp:SqlDataSource ID = SqlDataSource1 runat = server SelectCommand = SELECT City_Id,City_Name FROM City
ConnectionString = <%
ConnectionStrings:ConnectionString2 %> > < / asp :SqlDataSource >
< asp:DataList ID = DataList1 runat = server DataSourceID = SqlDataSource2 >
< ItemTemplate >
< ul >
< li > 名称:
< asp:标签 ID = nameLabel runat = server 文字 =' <% #Eval( name )%> ' / > < / li >
< li > 类别:
< asp:标签 ID = categoryLabel < span class =code-attribute> runat = server 文字 =' <% #Eval( category)%> ' / > < / li >
< li > City_Id:
< asp:Label ID = City_IdLabel runat = server 文字 =' <% #Eval( City_Id)%> ' / > < / li >
< / ul >
< / ItemTemplate >
< / asp:DataList >
< asp:SqlDataSource ID = SqlDataSource2 runat = server DataSourceMode = DataReader
SelectCommand = SELECT * FROM [Products] WHERE([City_Id] = @City_Id) ConnectionString = <%
hi i am using datalist in asp.net page,that display data from SQL DB at design time.
datalist show those candidate who live in Punjab state,but now after that i want more sorting in that data, i have a dropdownlist that display punjab state city,when user select a sepecific city
datalist show only that city candidate.
plz help
till i am using this code
<div id="dr1" style="width: 300px; padding-bottom: 1px; height: 630px; overflow: scroll">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server" CellPadding="4" RepeatLayout="Flow" DataSourceID="SqlDataSource1"
ForeColor="#333333" Width="300px" RepeatColumns="2" RepeatDirection="Horizontal">
<AlternatingItemStyle BackColor="White" ForeColor="#284775" />
<FooterStyle Font-Bold="True" ForeColor="White" BackColor="#5D7B9D" />
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#5D7B9D" />
<ItemStyle ForeColor="#333333" BackColor="#F7F6F3" />
<ItemTemplate>
<a class='iframe' href="my-business.aspx?nm='<%# Eval("Name") %>'">
<div class="card" style="min-height: 50px;">
<div class="fl">
<asp:Image ID="Image2" runat="server" Style="border: 1px solid #C6C6C6; float: left;
height: 50px; border-radius: 3px; width: 50px;" ImageUrl='<%# "AdminGetImage.aspx?id=" + Eval("id")%>' />
</div>
<div class="fl" style="margin-left: 7px; width: 215px;">
<div>
<asp:Label ID="Sent_FromLabel" Font-Size="10px" Style="text-transform: capitalize;
font-weight: bold;" Font-Names="Verdana" ForeColor="#014265" runat="server" Text='<%# Eval("Name") %>' />
</div>
<div>
<div>
<asp:Label ID="label3" runat="server" Font-Names="Verdana" ForeColor="#014265" Font-Size="10px"
Text='<%# Eval("Address") %>' />
</div>
<div style="margin-top: 2px;">
<asp:Label ID="Label1" Font-Size="10px" Font-Names="Verdana" ForeColor="#014265"
runat="server" Text='<%# Eval("Mobile") %>' />,
<asp:Label ID="Label4" Font-Size="10px" Font-Names="Verdana" ForeColor="#014265"
runat="server" Text='<%# Eval("Office") %>' />
</div>
<div>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("claim_status") %>' class="claim"></asp:Label>
</div>
</div>
</div>
<div class="clr">
</div>
</div>
</a>
</ItemTemplate>
<SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyArea %>"
SelectCommand="Sp_State_candidate" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter Name="state" QueryStringField="id" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
解决方案
ConnectionStrings:MyArea %>" SelectCommand="Sp_State_candidate" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:QueryStringParameter Name="state" QueryStringField="id" Type="String" /> </SelectParameters> </asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="city_name" DataValueField="city_id" AutoPostBack="true" BackColor="IndianRed" ForeColor="Snow"> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT City_Id, City_Name FROM City" ConnectionString="<%
ConnectionStrings:ConnectionString2 %>"></asp:SqlDataSource>
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource2"> <ItemTemplate> <ul> <li>name: <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' /></li> <li>category: <asp:Label ID="categoryLabel" runat="server" Text='<%# Eval("category") %>' /></li> <li>City_Id: <asp:Label ID="City_IdLabel" runat="server" Text='<%# Eval("City_Id") %>' /></li> </ul> </ItemTemplate> </asp:DataList> <asp:SqlDataSource ID="SqlDataSource2" runat="server" DataSourceMode="DataReader" SelectCommand="SELECT * FROM [Products] WHERE ([City_Id] = @City_Id)" ConnectionString="<%
这篇关于如何从sql访问数据并在运行时在datalist中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文