Reputation: 41
I've been working on a small project for a chatbox using ASP.NET and WebForms and basically I'm stuck trying to change the class of a panel so I can determine if the message should be placed on the left or the right side of the box depending on who sent it.
This is how I'm currently using all of this:
<div class="lv-body" id="ms-scrollbar" style="overflow:scroll; overflow-x: hidden; height:520px;">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="1000"></asp:Timer>
<asp:DataList ID="DataList3" runat="server">
<ItemTemplate>
<asp:Panel class="lv-item media" id="MessageBox" runat="server">
<div class="media-body">
<div class="ms-item">
<span class="glyphicon glyphicon-triangle-left" style="color:#000000;"></span>
<asp:Label ID="Message" runat="server" Text='<%# Bind("Message") %>'></asp:Label>
</div>
<small class="ms-date">
<span class="glyphicon glyphicon-time"></span>
<asp:Label Width="900px" ID="Date" runat="server" Text='<%# Bind("Date") %>'></asp:Label>
</small>
</div>
</asp:Panel>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
This is how I'm populating the values through CodeBehind:
public void LoadChatbox()
{
DateTime date = DateTime.Now;
string date3 = date.ToString("dd-MM-yyyy");
MySQL.MySqlCommand Cmd = new MySQL.MySqlCommand(MySQL.MySqlCommandType.SELECT);
Cmd.Select("helpdesk").Where("Sender", Label1.Text).And("Receiver", Label2.Text).Or("Sender", Label2.Text).And("Receiver", Label1.Text).Order("UniqueID");
MySQL.MySqlReader R = new MySQL.MySqlReader(Cmd);
DataList3.DataSource = R._dataset;
DataList3.DataBind();
}
Everything is working fine but basically I need a way to determine if the MessageBox (Panel) is displayed on the left or right side. Adding "right" to its class would do it but I would need a way to do that.
EDIT: The Label1 is representative of my name/id and the Label2 represents the name/id of the other member of the chat so these values can be used to determine if I sent it or the other person did.
Upvotes: 1
Views: 865
Reputation: 3230
I would say, in pseudo code :
<% if (Sender==me){ %>
<div class="media-body" style="text-align: right;">
...
</div>
else
<div class="media-body" style="text-align: left;">
...
</div>
<% } %>
Besides you'd better use a parametrized query, this line of code is dangerous :
Cmd.Select("helpdesk").Where("Sender", Label1.Text).And("Receiver", Label2.Text).Or("Sender", Label2.Text).And("Receiver", Label1.Text).Order("UniqueID");
Upvotes: 1