Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
XML
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Edit_about as.aspx.cs" Inherits="Default4" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script>
<title>jQuery Add More/Less link to Text</title>
<script type="text/javascript">
    $(function () {
        var showChar = 90, showtxt = "more", hidetxt = "less";
        $('.more').each(function () {
            var content = $(this).text();
            if (content.length > showChar) {
                var con = content.substr(0, showChar);
                var hcon = content.substr(showChar, content.length - showChar);
                var txt = con + '<span class="dots">...</span><span class="morecontent"><span>' + hcon + '</span>&nbsp;&nbsp;<a href="" class="moretxt">' + showtxt + '</a></span>';
                $(this).html(txt);
            }
        });
        $(".moretxt").click(function () {
            if ($(this).hasClass("sample")) {
                $(this).removeClass("sample");
                $(this).text(showtxt);
            } else {
                $(this).addClass("sample");
                $(this).text(hidetxt);
            }
            $(this).parent().prev().toggle();
            $(this).prev().toggle();
            return false;
        });
    });
</script>
<style type="text/css">
body{
font-family: Calibri, Arial;
margin: 0px;
padding: 0px;
}
.more {
width: 400px;

margin: 10px;
}
.morecontent span {
display: none;
}
</style>
    <style type="text/css">

        .item_button {
   color: #FFF;
   text-decoration:none;
   background: #007abe;
   padding: 5px 10px;
   vertical-align: middle;
   text-align:center;
   border:none;
   cursor:pointer;
    </style>
    <style type="text/css">


    .dlTable
    {
        border:double 1px #D9D9D9;
        width:250px;
        height:150px;
        text-align:left;
        vertical-align="center"
    }

 .d2table
 {
     width:200px;
     height:150;
  }

    </style>



</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:DataList ID="DataList1" runat="server" RepeatColumns = "2"
        RepeatLayout = "Table"  Width = "500px"
        onselectedindexchanged="DataList1_SelectedIndexChanged">
        <HeaderTemplate>
            <table cellspacing="0" cellpadding="0" bgcolor="#e6e5e5" style="width: 650px">
                <tr>
                    <td height="30px" bgcolor="#ffffff">
                    </td>
                </tr>
                <tr>
                    <td class="tourname_heading12" align="center">
                        View About US</td>
                </tr>
            </table>
        </HeaderTemplate>
        <ItemTemplate>
            <br />
            <table>
                <tr >
                    <td align="center" style="width: 500px">
                        <table cellpadding = "5px" cellspacing = "0" class="dlTable"  >
                            <tr>
                                <td align="center">
                                    <asp:Image ID="Image1" runat="server" ImageUrl = '<%# Eval("Image")%>'
                Width = "100px" Height = "100px"  />
                                </td>
                            </tr>
                        </table>
                        <table class="dlTable" >
                            <tr>
                                <td   class="d2table" align="center" colspan="3"   >
                                    <asp:Label ID="lbl_pname" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Partyname")%>' Font-Bold="true"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td  class="d2table" >
           PartyLeader</td>
                                <td>
                                    :</td>
                                <td>
                                    <asp:Label ID="lbl_pleder" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Partyleader")%>' Font-Bold="true"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td    class="d2table" >
           Party Started Year</td>
                                <td>
                                    :</td>
                                <td>
                                    <asp:Label ID="lbl_syear" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Startyear")%>' Font-Bold="true"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td class="d2table"    >
           Aim of The Party
                                </td>
                                <td>
                                    :</td>
                                <td>
                                    <asp:Label ID="lbl_aparty" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Aimparty")%>' Font-Bold="true"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td  class="d2table"  >
            History</td>
                                <td>
                                    :</td>
                                <td>
                                    <asp:Label ID="lbl_history" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "History")%>' Font-Bold="true"></asp:Label>
                                </td>
                            </tr>
                            <td align="right">
                                        <asp:LinkButton ID="lnkEdit" runat="server" CommandName="edit" Text="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Id") %>'  CssClass="item_button">Edit</asp:LinkButton>
                                        <asp:LinkButton Visible="false" ID="lnkUpdate" runat="server" CommandName="update" Text="Update" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "id") %>'  CssClass="item_button">Update</asp:LinkButton>
                                        <asp:LinkButton Visible="false" ID="lnkCancel" runat="server" CommandName="cancel" Text="Cancel" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "id") %>'  CssClass="item_button">Cancel</asp:LinkButton>
                                    </td>
                        </table>
                        <br />
                    </td>
                </tr>
            </table>
        </ItemTemplate>
    </asp:DataList>
</asp:Content

>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

public partial class Default4 : System.Web.UI.Page
{
string s1 = ConfigurationManager.ConnectionStrings["db"].ToString();
String fname, fpath, desc;
String spath;
protected void Page_Load(object sender, EventArgs e)
{

if (!Page.IsPostBack)
{
BindRepeater();
}
}
private void BindRepeater()
{
SqlConnection SqlCnn = new SqlConnection(s1);
SqlCommand SqlCmd = new SqlCommand("select * from mla_about", SqlCnn);
SqlDataAdapter SqlAd1 = new SqlDataAdapter(SqlCmd);
DataSet ds = new DataSet();
SqlAd1.Fill(ds, "mla_about");
DataList1.DataSource = ds;
DataList1.DataBind();
}
protected void DataList1_SelectedIndexChanged(object sender, DataListCommandEventArgs e)
{

LinkButton lnkUpdate = (LinkButton)e.Item.FindControl("lnkUpdate");
LinkButton lnkCancel = (LinkButton)e.Item.FindControl("lnkCancel");
LinkButton lnkEdit = (LinkButton)e.Item.FindControl("lnkEdit");

Label lbl_pname = (Label)e.Item.FindControl("lbl_pname");
TextBox txt_pname = (TextBox)e.Item.FindControl("txt_pname");
Label lbl_pleader = (Label)e.Item.FindControl("lbl_pleader");
TextBox txt_pleader = (TextBox)e.Item.FindControl("txt_syear");
Label lbl_syear = (Label)e.Item.FindControl("lbl_syear");
TextBox txt_syear = (TextBox)e.Item.FindControl("txt_pleader");
Label lbl_aparty = (Label)e.Item.FindControl("lbl_aparty");
TextBox txt_aparty = (TextBox)e.Item.FindControl("txt_aparty");
Label lbl_history = (Label)e.Item.FindControl("lbl_history");
TextBox txt_history = (TextBox)e.Item.FindControl("txt_history");
Label lbl_date = (Label)e.Item.FindControl("lbl_date");
Label lbl_id = (Label)e.Item.FindControl("lbl_id");
Image imgDB = (Image)e.Item.FindControl("imgDB");
FileUpload uploade1 = (FileUpload)e.Item.FindControl("uploade1");

if (e.CommandName == "edit")
{
lnkCancel.Visible = true;
lnkUpdate.Visible = true;
lnkEdit.Visible = false;
txt_pname.Visible = true;
lbl_pname.Visible = false;

uploade1.Visible = true;
txt_pleader.Visible = true;
lbl_pleader.Visible = false;

txt_syear.Visible = true;
lbl_syear.Visible = false;

txt_aparty.Visible = true;
lbl_aparty.Visible = false;

txt_history.Visible = true;
lbl_history.Visible = false;





}
if (e.CommandName == "cancel")
{
BindRepeater();
}
if (e.CommandName == "update")
{
if (uploade1.HasFile)
{
//Check File is available in Fileupload control and then upload to server path
fname = uploade1.FileName;
spath = @"~\latest_news\" + uploade1.FileName;
fpath = Server.MapPath("latest_news");
fpath = fpath + @"\" + uploade1.FileName;
uploade1.SaveAs(fpath);
SqlConnection SqlCnn = new SqlConnection(s1);

SqlCommand SqlCmd = new SqlCommand("update mla_about set Image=@spimage,Partyname=@sppartyname,Partyleader=@sppartyleader,Startyear=@spstartyear,Aimparty=@spaimparty,History=@sphistory where Id=@id", SqlCnn);

SqlCmd.Parameters.Add("@spimage", SqlDbType.VarChar).Value = spath;
SqlCmd.Parameters.Add("@sppartyname", SqlDbType.VarChar).Value = txt_pname.Text;
SqlCmd.Parameters.Add("@sppartyleader", SqlDbType.VarChar).Value = txt_pleader.Text;
SqlCmd.Parameters.Add("@spstartyear", SqlDbType.VarChar).Value = txt_syear.Text;
SqlCmd.Parameters.Add("@sphistory", SqlDbType.VarChar).Value = txt_history.Text;

SqlCmd.Parameters.Add("@id", SqlDbType.VarChar).Value = e.CommandArgument;
try
{
SqlCnn.Open();
SqlCmd.ExecuteNonQuery();

}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
if (SqlCnn.State == ConnectionState.Open)
SqlCnn.Close();
}
BindRepeater();
}


SqlConnection Cnn = new SqlConnection(s1);

SqlCommand Cmd = new SqlCommand("update mla_about set Partyname=@sppartyname,Partyleader=@sppartyleader,Startyear=@spstartyear,Aimparty=@spaimparty,History=@sphistory where Id=@id", Cnn);

Cmd.Parameters.Add("@sppartyname", SqlDbType.VarChar).Value = txt_pname.Text;
Cmd.Parameters.Add("@sppartyleader", SqlDbType.VarChar).Value = txt_pleader.Text;
Cmd.Parameters.Add("@spstartyear", SqlDbType.VarChar).Value = txt_syear.Text;
Cmd.Parameters.Add("@sphistory", SqlDbType.VarChar).Value = txt_history.Text;
Cmd.Parameters.Add("@id", SqlDbType.VarChar).Value = e.CommandArgument;
try
{
Cnn.Open();
Cmd.ExecuteNonQuery();

}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
if (Cnn.State == ConnectionState.Open)
Cnn.Close();
}
BindRepeater();
}
}
}
Posted
Updated 21-May-14 0:50am
v2
Comments
ZurdoDev 21-May-14 8:03am    
Please debug your code and then edit your question to show only the relevant code so that we can help you out.
Sunasara Imdadhusen 21-May-14 8:43am    
Really you have to debug your code thoroughly and try to identify issue. because no one can read and understand your entire code over here. So it will no chance to get correct answer from the experts.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900