在datalist中保存项目 [英] Save item in datalist

查看:71
本文介绍了在datalist中保存项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数据列表的aspx代码,在其中我有一个名为txtComment的文本框。如何保存在文本框中输入的值。请帮我解决这个问题。





我需要将其保存在数据库中。 />


I have an aspx code contains data list and inside it I have a textbox named "txtComment". How will I save value entered in textbox. Please help me to solve this.


I need to save it in database .

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

        ondatabinding="DataList1_DataBinding">

           <asp:GridView runat="server" ID="grdPrevComment" AutoGenerateColumns="false" BorderStyle="Solid"

                                            BorderColor="Red" OnRowDataBound="grdPrevComment_DataBound" Width="100%">


                                                <asp:TemplateField HeaderText="Comment">

                                                        <asp:Label runat="server" ID="lblCostElement" Text='<%# Eval("COC") %>' />

                                                    <HeaderStyle HorizontalAlign="Left" />



                                                 <asp:TemplateField HeaderText="Commented by">

                                                        <asp:Label runat="server" ID="lblCostElement" Text='<%# Eval("Name") %>' />

                                                    <HeaderStyle HorizontalAlign="Left" />

           <br />
          <div class="tablecoloumn_20L">
                        <asp:Label ID="lblComment" runat="server" Text="Comment" ViewStateMode="Disabled" CssClass="lable"/>
                    </div>
                    <div class="tablecoloumn_80R">
                        <asp:TextBox ID="txtComment" runat="server" TextMode="MultiLine"

                            CssClass="textarea_m" Width="503px" Height="81px"

                        onkeypress="return ImposeMaxLength(event,this,5000);"  MaxLength="5000"

                        onkeyup ="return LimitLength(this,5000);"

                            ondblclick="this.focus();this.select()" onfocus="SelectAll(this.id);"

                            TabIndex="3" />
                    </div>
          <%-- <asp:LinkButton ID="lnkSubmit" runat="server" onclick="lnkSubmit_Click">Submit--%>
          <asp:LinkButton ID="lnkBtnSubmit" ValidationGroup="requied" onkeyup="Button_SpaceBar(event,this)" CssClass="saveButton" Text="Submit"

                             runat="server" TabIndex="4" OnClick="lnkBtnSubmit_Click" >







这个是我的aspx代码。




This is my aspx code.

推荐答案

嗨...

看到这个用name和imgurl保存数据库中的图像。

在.aspx

Hi...
See this to save images in database with name and imgurl.
In .aspx
<<asp:fileupload id="imgful" runat="server" height="25px" style="font-weight: 700" xmlns:asp="#unknown" />
<asp:button id=""btnimg"" runat=""server"" text=""SaveProduct"" onclick=""btnimg_Click"<br" mode="hold" xmlns:asp="#unknown" />            ForeColor="DeepPink" style="font-weight: 700" Width="99px" Height="28px"/>



在aspx.cs中:


In aspx.cs:

//Get Filename from fileupload control
                string filename = Path.GetFileName(imgful.PostedFile.FileName);
                //Save images into Images folder
                imgful.SaveAs(Server.MapPath("~/Images/" + filename));
cmd = new MySqlCommand("Insert into Items(ProductName,ImageUrl,Cost,DateTime) values(@ImageName,@ImagePath,'" + txtcost.Text + "','" + dt + "')", con);

                        //Passing parameters to query
                        cmd.Parameters.AddWithValue("@ImageName", filename);
                        cmd.Parameters.AddWithValue("@ImagePath", "~/Images/" + filename);
                        con.Open();
                        cmd.ExecuteNonQuery();
                        //Close dbconnection
                        con.Close();





看到这是用于在datalist中显示图像。

在aspx中:



See this is for display images in datalist.
In aspx:

<asp:DataList ID="DataList1" runat="server" Height="82px"

        ItemStyle-HorizontalAlign="Center" RepeatColumns="3" Width="180px" EnableViewState="true">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
        <ItemTemplate>
        <asp:Image ID="img1" ImageUrl='<%# Bind("Name", "~/Images/{0}") %>' Width="250" Height="180" runat="server" />
        <asp:HyperLink ID="HyperLink1" Text='<%# Bind("Name") %>' NavigateUrl='<%# Bind("Name", "~/Images/{0}") %>' runat="server"/>
            </ItemTemplate>
    </asp:DataList>



在aspx.cs中:


In aspx.cs:

DirectoryInfo dir = new DirectoryInfo(MapPath("Images"));
            FileInfo[] files = dir.GetFiles();
            ArrayList listitems = new ArrayList();
            foreach (FileInfo info in files)
            {
               listitems.Add(info);
            }
            // bind images on conditional
            adsource = new PagedDataSource();
            adsource.DataSource = listitems;
            // display no of images
            adsource.PageSize = 5;
            adsource.AllowPaging = true;
            
            DataList1.DataSource = adsource;
            DataList1.DataBind();



Thnak u。


Thnak u.


这篇关于在datalist中保存项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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