I'm having a problem which, for the life of me, I can't figure out.
I have a listbox ( ID: CommentsListBox ) inside of a splitter control. The listbox should be getting it's data from a SqlDataSource ( ID:CommentsDataSource ), but it seems it wont bind to the datasource, the code never actual executes the Comments_ItemDataBound method. I have no idea why. I know the select command for the sql datasource is good, it executes just fine in sql server and does return results. Please help.
aspx file
aspx.cs file
I have a listbox ( ID: CommentsListBox ) inside of a splitter control. The listbox should be getting it's data from a SqlDataSource ( ID:CommentsDataSource ), but it seems it wont bind to the datasource, the code never actual executes the Comments_ItemDataBound method. I have no idea why. I know the select command for the sql datasource is good, it executes just fine in sql server and does return results. Please help.
aspx file
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Workbin_Item.aspx.cs" Inherits="Client_Workbin_Item" %> |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head runat="server"> |
<title>Untitled Page</title> |
<style> |
html, body, form |
{ |
margin:0; |
padding:0; |
height:100%; |
} |
</style> |
</head> |
<body runat="server"> |
<form runat="server"> |
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePartialRendering="true" /> |
<telerik:RadFormDecorator ID="FormDecorator" runat="server" DecoratedControls="All"/> |
<div style="height:100%;"> |
<telerik:RadSplitter ID="RadSplitter1" runat="server" Width="100%" Height="100%"> |
<telerik:RadPane ID="ContentPane" runat="server" > |
Content Goes Here... |
</telerik:RadPane> |
<telerik:RadSplitBar ID="RadSplitBar1" runat="server" CollapseMode="Backward" EnableResize="false"/> |
<telerik:RadPane ID="CommentsPane" runat="server" Width="209" > |
<telerik:RadAjaxPanel ID="CommentPanel" runat="server"> |
<telerik:RadSplitter ID="CommentsSplitter" runat="server" Orientation="Horizontal" > |
<telerik:RadPane ID="CommentInsert" runat="server" Height="100" Scrolling="None" > |
<center> |
<telerik:RadTextBox ID="NewComment" runat="server" TextMode="MultiLine" EmptyMessage="Add Comment Here..." |
Rows="3" Width="95%" style="margin-top:5px;" /> |
<asp:Button ID="InsertCommentBttn" runat="server" Text="Add Comment" OnClick="InsertComment"/> |
<asp:Button ID="RefreshListBttn" runat="server" Text="Refresh List" OnClick="RefreshList" /> |
</center> |
</telerik:RadPane> |
<telerik:RadPane ID="Comments" runat="server"> |
<telerik:RadListBox ID="CommentsListBox" runat="server" Height="100%" Width="100%" |
DataSouceID="CommentsDataSource" DataKeyField="Comment_ID" OnItemDataBound="Comments_ItemDataBound" > |
</telerik:RadListBox> |
</telerik:RadPane> |
</telerik:RadSplitter> |
</telerik:RadAjaxPanel> |
</telerik:RadPane> |
</telerik:RadSplitter> |
</div> |
<asp:SqlDataSource runat="server" ID="CommentsDataSource" ConnectionString="<%$ ConnectionStrings:FCRCConnectionString %>" |
SelectCommand="SELECT W_I_C.Comment, W_I_C.DateTime, U.First_Name, U.Last_Name, W_I_C.Comment_ID |
FROM Workbin_Item_Comments AS W_I_C INNER JOIN |
Users AS U ON W_I_C.User_ID = U.User_ID |
WHERE (W_I_C.Workbin_Item_ID = @Item_ID) |
ORDER BY W_I_C.DateTime DESC" |
> |
<SelectParameters> |
<asp:QueryStringParameter Name="Item_ID" QueryStringField="Item_ID" DbType="Int32" DefaultValue='12'/> |
</SelectParameters> |
</asp:SqlDataSource> |
</form> |
</body> |
</html> |
aspx.cs file
public partial class Client_Workbin_Item : System.Web.UI.Page |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
Session["User_ID"] = "100"; //Here for testing purposes |
} |
protected void Comments_ItemDataBound(object sender, RadListBoxItemEventArgs e) |
{ |
GM.Track_User_Action("databound"); |
DataRowView dataSourceRow = (DataRowView)e.Item.DataItem; |
e.Item.Text = dataSourceRow["First_Name"].ToString() + " " + dataSourceRow["Last_Name"].ToString() + "<br />" + dataSourceRow["Comment"].ToString(); |
} |
protected void RefreshList(Object sender, EventArgs e) |
{ |
GM.Track_User_Action("refresh"); |
CommentsDataSource.Select(new DataSourceSelectArguments()); |
CommentsListBox.DataBind(); |
} |
protected void InsertComment(Object sender, EventArgs e) |
{ |
GM.Track_User_Action("insert"); |
try |
{ |
MySqlConnection mySql = new Globals.MySqlConnection(); |
SqlCommand cmd = mySql.CreateConn().CreateCommand(); |
cmd.CommandText = "INSERT INTO Workbin_Item_Comments (Comment, Workbin_Item_ID, User_ID) VALUES (@Comment, @Item_ID, @User_ID)"; |
cmd.Parameters.Add("@Comment", SqlDbType.VarChar).Value = NewComment.Text; |
cmd.Parameters.Add("@Item_ID", SqlDbType.Int).Value = Request.QueryString["Item_ID"].ToString(); |
cmd.Parameters.Add("@User_ID", SqlDbType.Int).Value = Session["User_ID"].ToString(); |
cmd.ExecuteNonQuery(); |
cmd.Dispose(); |
mySql.CloseConn(); |
NewComment.Text = null; |
} |
catch (Exception error) |
{ |
GM.Track_User_Action("Error inserting Workbin Item '"+Request.QueryString["Item_ID"].ToString()+"' Comment Insert: " + error.Message); |
} |
} |
} |