我想在datalist中获取数据库值,然后单击想要将值传递给下一页 [英] I want to get database value in datalist and then on click want to pass the value to next page

查看:49
本文介绍了我想在datalist中获取数据库值,然后单击想要将值传递给下一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的源代码: -



 <   asp:DataList     ID   =  DataList1    runat   =  server  

DataKeyNames < span class =code-keyword> = Img xmlns:asp = < span class =code-keyword>#unknown RepeatDirection = 水平 RepeatColumns = 3 >

< ItemTemplate >
< ul >
< li >
< < span class =code-leadattribute> img src =' cap / <% #Eval( Img%> ' height = 150px width = 210px > < < span class =code-leadattribute> / img >
< label id = label >
< asp:LinkBut​​ton id = lnk1 runat = server

文字 =' cap / <% #Eval( Img%> ' onclick = lnk1_Click > 查看详细信息< / asp:LinkBut​​ton >
< / label >
< span class =code-keyword>< / li >

< / ul >
< / ItemTemplate > ;

< / asp:DataList >







点击按钮我正在执行此功能: -



  protected   void  lnk1_Click( object  sender,EventArgs e)
{
LinkBut​​ton lnk1 = sender as LinkBut​​ton;
Label2.Text =((LinkBut​​ton)DataList1.Items [ 0 ]。FindControl( lnk1))。文字;
Response.Redirect( album.aspx?pid = + Label2.Text);
}







问题是当我点击按钮时它将值传递为'查看详细信息',当我删除文本'查看详细信息'时,我得到的值为上限/<%#Eval(Img)%>。我想从我的数据库中获取值cap.jpg。



请帮助!!

解决方案

我不建议你在这种情况下使用多页设计。



让我们看看。它实际上取决于您从数据库获得多少数据,但通常结果集相当大。要将所有检索到的数据传递到另一个页面,您需要序列化数据,将其存储在会话数据中并从下一页的会话存储中检索它,然后将其反序列化。这很可能,但是......所有这些的开销可能非常大,以至于再次从数据库中检索相同的数据可能要容易得多。你能看出这一点吗?



所以,这是考虑单页设计方案的一个很好的理由。在视觉上,它看起来可能与多页面设计完全相同(如果它甚至有意义):在单个页面上,您可以拥有许多隐藏的组件。当您转到下一个步骤(曾经是一个不同的页面)时,您隐藏不需要的HTML元素并显示想要的那些。最简单的设计可能是这样:在同一页面上有几个对等的div元素,而不是单独的页面。每个这样的div代表曾经是一个页面,具有相同的内容。您可以一次显示一个div,在导航线上来回移动。



-SA


谢谢我得到了答案: -



 <   asp:DataList     runat  < span class =code-keyword> =  server    ID   =  DataList1    RepeatColumns   =  3    RepeatDirection   = 水平 >  
< ItemTemplate >
< li >
< img src =' cap / <% #Eval( Img%> ' alt = height = 150px width = 210px > < ; / img >
< label id = label >
< a href = < ;% designcap.aspx?pid = + Eval( ID%> > 查看详细信息< / a > < / label >
< / li >
< / ItemTemplate >
< / asp:DataList >


This is my source code:-

<asp:DataList ID="DataList1" runat="server"

                                    DataKeyNames="Img" xmlns:asp="#unknown" RepeatDirection="Horizontal" RepeatColumns="3" >

                                      <ItemTemplate>
                                      <ul>
                                        <li>
                                           <img src='cap/<%#Eval("Img") %>' height="150px" width="210px"></img>
                                           <label id="label">
                                                <asp:LinkButton id="lnk1" runat="server"

                                               Text='cap/<%#Eval("Img") %>' onclick="lnk1_Click" >View Details</asp:LinkButton>
                                               </label>
                                        </li>

                                      </ul>
                                      </ItemTemplate>

                                    </asp:DataList>




And on button click I'm doing the function:-

protected void lnk1_Click(object sender, EventArgs e)
    {
        LinkButton lnk1 = sender as LinkButton;
        Label2.Text = ((LinkButton)DataList1.Items[0].FindControl("lnk1")).Text;
        Response.Redirect("album.aspx?pid=" + Label2.Text);
    }




The problem is when I click the button it pass the value as 'View Details' and when I remove the text 'View Details' I get the value as "cap/<%#Eval("Img") %>". I want to get the value from my database as "cap.jpg".

Please HELP!!

解决方案

I would not advise you to use the multi-page design in such cases.

Let's see. It actually depends on how much data do you get from the database, but usually result sets are considerably big. To pass all the retrieved data to another page, you need to serialize the data, store it in the session data and retrieve it from session storage in the next page, then deserialize it back. This is quite possible, but… The overhead of all this can be so considerable that it might be much easier to retrieve the same data from the database again. Can you see the point?

So, this is a good reason to think at the single-page design alternative. Visually, it may look exactly the same as multi-page design (if it even makes sense): on the single page, you can have many hidden component. When you move to next "step" (what used to be a different page), you hide unwanted HTML element and show wanted ones. The simplest design could be this: instead of separate pages, you have several peer "div" elements on the same page. Each such "div" represents what used to be a page, has the same content. You can show one "div" at a time, moving back or forth on your navigation line.

—SA


Thanks I got the answer:-

<asp:DataList runat="server" ID="DataList1" RepeatColumns="3" RepeatDirection="Horizontal">
                        <ItemTemplate>
                            <li>
                                <img src='cap/<%#Eval("Img") %>' alt="" height="150px" width="210px"></img>
                                <label id="label">
                                    <a href="<%#"designcap.aspx?pid="+Eval("ID") %>">View Details</a></label>
                            </li>
                        </ItemTemplate>
                    </asp:DataList>


这篇关于我想在datalist中获取数据库值,然后单击想要将值传递给下一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆