www.webdeveloper.com
Results 1 to 4 of 4

Thread: Editing contents of Datalist

  1. #1
    Join Date
    May 2005
    Posts
    47

    Editing contents of Datalist

    Hi guys,

    I've set up a datalist, and each row has an 'edit' button, which triggers the editcommand, so the user can edit the contents of the row.

    This works OK. However, once the user makes changes to the fields, then clicks 'Update', no changes are made. In fact, I don't think it is even picking up the new values from each field.

    To further confuse matters, I have to use FCKEditor for some of the input boxes.

    Please can anyone help, as this is driving me up the wall!

    The code for the front-end page is as follows:

    <aspataList id="adminList" style="Z-INDEX: 101; LEFT: 128px; POSITION: absolute; TOP: 136px"
    runat="server" Width="312" Height="320" onEditCommand="adminListEditHandler" onUpdateCommand="adminListUpdateHandler" onCancelCommand="adminListCancelHandler">

    <ItemTemplate>
    <p><%# DataBinder.Eval(Container.DataItem, "LenderName") %></p>
    <p><img src="./img/lenderLogos/<%# DataBinder.Eval(Container.DataItem, "LenderLogo") %>"></p>
    <p><%# DataBinder.Eval(Container.DataItem, "LenderStrengths") %></p>
    <p><%# DataBinder.Eval(Container.DataItem, "LenderKFI") %></p>
    <p><%# DataBinder.Eval(Container.DataItem, "LenderDownloads") %></p>
    <asp:linkbutton runat="server" commandname="edit" text='Edit' />
    </ItemTemplate>

    <EditItemTemplate>
    <p><%# DataBinder.Eval(Container.DataItem, "LenderName") %></p>
    <P>Lender name: <asp:textbox id="txtLenderName" runat="server" text='<%# DataBinder.Eval(Container.DataItem, "LenderName") %>' />
    <p>Logo: <input id="UploadImage" type="file" name="UploadFile" runat="server"></p>
    <P><INPUT id="UploadKFI" type="file" name="UploadKFI" runat="server"></P>
    <P>Key strengths:<br>
    <FCKeditorV2:FCKeditor id="FCKLenderStrengths" runat="server" ToolbarSet="Basic"></FCKeditorV2:FCKeditor></P>
    <P>KFI help:<br>
    <fckeditorv2:FCKeditor id="FCKLenderKFI" runat="server" Width="400px" Height="200px"></fckeditorv2:FCKeditor></P>

    <P><asp:label id="lblMessage" runat="server"></asp:label></P>
    <P>Downloads:<br>
    <fckeditorv2:FCKeditor id="FCKLenderDownloads" runat="server" Width="400px" Height="200px"></fckeditorv2:FCKeditor></P>
    <p><asp:linkbutton commandname="update" runat="server" text="Update" /></p>
    <p><asp:linkbutton commandname="cancel" runat="server" text="Cancel" /></p>
    </EditItemTemplate>
    </aspataList>

    -----------

    The code for the back-end is as follows:

    public void adminListUpdateHandler (object src, DataListCommandEventArgs e )
    {
    string strLenderName = ((TextBox)e.Item.FindControl("txtLenderName")).Text;
    string strLenderStrengths = ((FredCK.FCKeditorV2.FCKeditor)e.Item.FindControl("FCKLenderStrengths")).Value;
    string strLenderKFI = ((FredCK.FCKeditorV2.FCKeditor)e.Item.FindControl("FCKLenderKFI")).Value;
    string strLenderDownloads = ((FredCK.FCKeditorV2.FCKeditor)e.Item.FindControl("FCKLenderDownloads")).Value;
    string strLenderKFILogo = "logo";
    string strLenderKFIFile = "file";
    string _path = Server.MapPath("./img/lenderLogos/");
    HttpFileCollection HttpFiles = Request.Files;
    AddLender(strLenderName, strLenderKFILogo, strLenderStrengths, strLenderKFIFile, strLenderDownloads);
    adminList.EditItemIndex = -1;
    GetList();
    }

    private void GetList()
    {
    SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
    SqlCommand myCmd = new SqlCommand("sp_GetLenders", myConn);
    myCmd.CommandType = CommandType.StoredProcedure;
    myConn.Open();
    SqlDataReader reader = myCmd.ExecuteReader();

    this.adminList.DataSource = reader;
    this.adminList.DataBind();
    }

    private bool AddLender(string strLenderName, string strImageName, string strLenderStrengths, string strLenderKFI, string strLenderDownloads)
    {
    SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
    SqlCommand myCmd = new SqlCommand("sp_AddLender", myConn);
    myCmd.CommandType = CommandType.StoredProcedure;

    SqlParameter objParam1;
    SqlParameter objParam2;
    SqlParameter objParam3;
    SqlParameter objParam4;
    SqlParameter objParam5;

    objParam1 = myCmd.Parameters.Add ("@LenderName", SqlDbType.VarChar);
    objParam2 = myCmd.Parameters.Add ("@LenderLogo", SqlDbType.VarChar);
    objParam3 = myCmd.Parameters.Add ("@LenderStrengths", SqlDbType.VarChar);
    objParam4 = myCmd.Parameters.Add ("@LenderKFI", SqlDbType.VarChar);
    objParam5 = myCmd.Parameters.Add ("@LenderDownloads", SqlDbType.VarChar);

    objParam1.Value = strLenderName;
    objParam2.Value = strImageName;
    objParam3.Value = strLenderStrengths;
    objParam4.Value = strLenderKFI;
    objParam5.Value = strLenderDownloads;

    try
    {
    if (myConn.State.Equals(ConnectionState.Closed))
    {
    myConn.Open();
    myCmd.ExecuteNonQuery();
    return true;
    }
    else
    {
    myConn.Close();
    return true;
    }
    }
    catch (Exception ex)
    {
    lblMessage.Text = ex + "We are currently experiencing technical problems. Please try again later.";
    return false;
    }
    }

  2. #2
    Join Date
    May 2005
    Posts
    47
    I fixed this problem by adding a

    if(!Page.IsPostBack)

    The problem I am now having is, I would like to add two file browsing controls to the edit template, e.g:

    <input id="UploadImage" type="file" name="UploadFile" runat="server">
    <INPUT id="UploadKFI" type="file" name="UploadKFI" runat="server">

    But I do not now how to set this up in the Update handler. The following code would work ordinarily, but it doesn't in this context:

    string strLenderKFILogo = Path.GetFileName(UploadImage.PostedFile.FileName);
    string strLenderKFIFile = Path.GetFileName(UploadKFI.PostedFile.FileName);

    Can I use FindControl as I did with the other input controls?

  3. #3
    Join Date
    May 2005
    Posts
    47
    I've now solved this, it was easier than I thought...

    string strLenderKFILogoPath = ((HtmlInputFile)e.Item.FindControl("UploadImage")).Value;
    string strLenderKFIFilePath = ((HtmlInputFile)e.Item.FindControl("UploadKFI")).Value;

    strLenderKFILogo = Path.GetFileName(strLenderKFILogoPath);
    strLenderKFIFile = Path.GetFileName(strLenderKFIFilePath);

  4. #4
    Join Date
    Oct 2005
    Posts
    189
    Hi

    Very smart...............
    ------------------------------------------
    Regards
    Abhishek Goel
    Software Developer in handshakeit (Handshake Infotech Pvt Ltd.)
    ------------------------------------------
    ActiveX controls

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles