超链接在asp.net数据库中检索数据 [英] hyperlink to retrieve data from a database in asp.net
问题描述
我在开发的显示存储在数据库(SQL Server)的不同作业的作业门户。我使用ASP.NET和HTML。
我 JOB_TITLE
和数据库表中是唯一的job_id
。我创建超链接 JOB_TITLE
这是从数据库中检索。现在我想通过点击 JOB_TITLE
那份工作,显示不同的页面上特定作业的详细信息。
我需要作业ID
为该特定的工作其详细信息我想旁边显示的超链接的页面上。之所以不使用 JOB_TITLE
而不是作业ID
是 JOB_TITLE
不是唯一的,但作业ID
是。请告诉我如何实现这一目标,或者如果你有另一种解决方案?
下面是一些示例code此:
(jobs.aspx)
< ASP:SqlDataSource的ID =SqlDataSource1=服务器的ConnectionString =<%$的ConnectionStrings:JobPortalConnectionString2%>中的SelectCommand =SELECT [JOB_TITLE],[说明] FROM [就业]>< / ASP:SqlDataSource的>
< ASP:ListView控件ID =ListView1的=服务器的DataSourceID =SqlDataSource1>
< AlternatingItemTemplate>
<强>职位名称:LT; / STRONG>
<跨度风格=>
< ASP:标签ID =job_titleLabel=服务器文本='<%#的eval(JOB_TITLE)%>' />
< BR />
<强>简介:< / STRONG>
< ASP:标签ID =descriptionLabel=服务器文本='<%#的eval(说明)%GT;' />
< BR />
< BR />
< / SPAN>
< / AlternatingItemTemplate>
<&EditItemTemplate的GT;
<跨度风格=> JOB_TITLE:
< ASP:文本框ID =job_titleTextBox=服务器文本='<%#绑定(JOB_TITLE)%>' />
< BR />
描述:
< ASP:文本框ID =descriptionTextBox=服务器文本='<%#绑定(说明)%GT;' />
< BR />
< ASP:按钮的ID =UpdateButton=服务器的CommandName =更新文本=更新/>
< ASP:按钮的ID =CancelButton=服务器的CommandName =取消文本=取消/>
< BR />< BR />< / SPAN>
< / EditItemTemplate中>
< EmptyDataTemplate>
<跨度中的溶液返回任何数据< / SPAN>
< / EmptyDataTemplate>
<&InsertTemplate则GT;
<跨度风格=> JOB_TITLE:
< ASP:文本框ID =job_titleTextBox=服务器文本='<%#绑定(JOB_TITLE)%>' />
< BR />简介:
< ASP:文本框ID =descriptionTextBox=服务器文本='<%#绑定(说明)%GT;' />
< BR />
< ASP:按钮的ID =InsertButton=服务器的CommandName =插入文本=插入/>
< ASP:按钮的ID =CancelButton=服务器的CommandName =取消文本=清除/>
< BR />< BR />< / SPAN>
< / InsertTemplate则>
<&ItemTemplate中GT;
<强>职位名称:LT; / STRONG>
<跨度风格=>
< ASP:标签ID =job_titleLabel=服务器文本='<%#的eval(JOB_TITLE)%>'>< / ASP:标签>
< BR />
<强>简介:< / STRONG>
< ASP:标签ID =descriptionLabel=服务器文本='<%#的eval(说明)%GT;'>< / ASP:标签>
< BR />
< BR />
< / SPAN>
< / ItemTemplate中>
<&LayoutTemplate模板GT;
< DIV ID =itemPlaceholderContainer=服务器的风格=>
<跨度=服务器ID =itemPlaceholder/>
&安培; NBSP;< / SPAN>< / DIV>
< ASP:按钮的ID =Button1的=服务器HEIGHT =30像素的OnClick =Button1_Click1文本=立即申请WIDTH =100像素/>
< DIV的风格=>
< ASP:DataPager的ID =DataPager1=服务器>
<&领域GT;
< ASP:接下来previousPagerField按钮类型=按钮ShowFirstPageButton =真ShowNextPageButton =FALSE显示previousPageButton =FALSE/>
< ASP:NumericPagerField />
< ASP:接下来previousPagerField按钮类型=按钮ShowLastPageButton =真ShowNextPageButton =FALSE显示previousPageButton =FALSE/>
< /场>
< / ASP:DataPager的>
< / DIV>
< / LayoutTemplate模板>
< SelectedItemTemplate>
<跨度风格=> JOB_TITLE:
< ASP:标签ID =job_titleLabel=服务器文本='<%#的eval(JOB_TITLE)%>' />
< BR />
描述:
< ASP:标签ID =descriptionLabel=服务器文本='<%#的eval(说明)%GT;' />
< BR />
< / DIV>
它看起来像你想有一个像这样的网址:
blabla-your-website.com/fisrt-job-title
blabla-your-website.com/second-job-title
blabla-your-website.com/other-job-title
但你说:
JOB_TITLE不是唯一的,但作业ID是
块引用>所以这是不可能的事情。这种常见的解决方案是在您的网址在同一时间使用ID和标题:
blabla-your-website.com/1-fisrt-job-title
blabla-your-website.com/22-second-job-title
blabla-your-website.com/333-other-job-title其中,1,22,和333是特定的工作唯一的ID。
如果你的标题是独一无二的,这是很容易做到的。看看<一个href=\"https://github.com/ayende/RaccoonBlog/blob/master/RaccoonBlog.Web/Infrastructure/Common/SlugConverter.cs\"相对=nofollow> RacoonBlog的SlugConverter 。它用于您的标题转换为这样的URL(从RacoonBlog测试code):
VAR的结果= SlugConverter.TitleToSlug(文件的建模:拍卖与放大器;投标);
Assert.Equal(基于文档的建模,拍卖,竞价,结果); 结果= SlugConverter.TitleToSlug(雇用的问题,电话簿);
Assert.Equal(招聘-问题最电话簿,结果);I am developing job portal which displays different jobs stored in database (SQL Server). I am using ASP.NET and HTML.
I have
job_title
andunique job_id
in database table. I have created hyperlink forjob_title
which is retrieved from database. Now I want to display the details of that particular job on a different page by clickingjob_title
of that job.I need
job_id
for that particular job whose details I want to display on next hyper linked page. The reason for not to usejob_title
instead ofjob_id
is thatjob_title
is not unique, butjob_id
is. Please tell me how to accomplish that or if you have another solution?Here is some sample code for this:
(jobs.aspx)
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:JobPortalConnectionString2 %>" SelectCommand="SELECT [job_title], [description] FROM [jobs]"></asp:SqlDataSource> <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1"> <AlternatingItemTemplate> <strong>Job Title:</strong> <span style=""> <asp:Label ID="job_titleLabel" runat="server" Text='<%# Eval("job_title") %>' /> <br /> <strong>Description:</strong> <asp:Label ID="descriptionLabel" runat="server" Text='<%# Eval("description") %>' /> <br /> <br /> </span> </AlternatingItemTemplate> <EditItemTemplate> <span style="">job_title: <asp:TextBox ID="job_titleTextBox" runat="server" Text='<%# Bind("job_title") %>' /> <br /> description: <asp:TextBox ID="descriptionTextBox" runat="server" Text='<%# Bind("description") %>' /> <br /> <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" /> <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" /> <br /><br /></span> </EditItemTemplate> <EmptyDataTemplate> <span>No data was returned.</span> </EmptyDataTemplate> <InsertItemTemplate> <span style="">job_title: <asp:TextBox ID="job_titleTextBox" runat="server" Text='<%# Bind("job_title") %>' /> <br />description: <asp:TextBox ID="descriptionTextBox" runat="server" Text='<%# Bind("description") %>' /> <br /> <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" /> <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" /> <br /><br /></span> </InsertItemTemplate> <ItemTemplate> <strong>Job Title:</strong> <span style=""> <asp:Label ID="job_titleLabel" runat="server" Text='<%# Eval("job_title") %>'></asp:Label> <br /> <strong>Description:</strong> <asp:Label ID="descriptionLabel" runat="server" Text='<%# Eval("description") %>'></asp:Label> <br /> <br/> </span> </ItemTemplate> <LayoutTemplate> <div id="itemPlaceholderContainer" runat="server" style=""> <span runat="server" id="itemPlaceholder" /> </span></div> <asp:Button ID="Button1" runat="server" Height="30px" OnClick="Button1_Click1" Text="Apply Now" Width="100px" /> <div style=""> <asp:DataPager ID="DataPager1" runat="server"> <Fields> <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" /> <asp:NumericPagerField /> <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" /> </Fields> </asp:DataPager> </div> </LayoutTemplate> <SelectedItemTemplate> <span style="">job_title: <asp:Label ID="job_titleLabel" runat="server" Text='<%# Eval("job_title") %>' /> <br /> description: <asp:Label ID="descriptionLabel" runat="server" Text='<%# Eval("description") %>' /> <br />
</div>
解决方案It looks like you wanna have urls like this:
blabla-your-website.com/fisrt-job-title blabla-your-website.com/second-job-title blabla-your-website.com/other-job-title
But you said:
job_title is not unique, but job_id is
So it's not possible to do. The common solution for this is to use ids and titles at the same time in your url:
blabla-your-website.com/1-fisrt-job-title blabla-your-website.com/22-second-job-title blabla-your-website.com/333-other-job-title
Where 1, 22, and 333 are unique ids for particular job.
If your titles are unique, it's quite easy to do. Take a look at RacoonBlog's SlugConverter. It is used to convert your titles to urls like this (code from RacoonBlog tests):
var result = SlugConverter.TitleToSlug("Document based modeling: Auctions & Bids"); Assert.Equal("document-based-modeling-auctions-bids", result); result = SlugConverter.TitleToSlug("Hiring Questions–The phone book"); Assert.Equal("hiring-questions-the-phone-book", result);
这篇关于超链接在asp.net数据库中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!