invisible kid
04-01-2006, 01:08 PM
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:
<asp:DataList 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>
</asp:DataList>
-----------
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;
}
}
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:
<asp:DataList 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>
</asp:DataList>
-----------
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;
}
}