ItemDataBound slowing my page rendering - c#

1My first question ever here, forgive if I am not fluent in tech language because I am a self taught developer from deep Africa Mozambique, thanks to this site.
My question is I have a
public void topicView_ItemDataBound(object sender,e)
In my code behind for a particular aspx page with a repeater, that receives its info from a datatable (if my terminology is correct.) The ItemDataBound event is to arrange my controls in a repeater for the purpose of hiding, disabling and showing other controls according to the determined criterias. Now I have noticed that the ItemDataBound event is slowing my page load time by some 20 to 40 seconds which is really bad, even on post back. When i remove the ItemDataBound events. I am running smoothly. But i can't work with out the ItemDataBound event since its the only way i know how to arrange a repeater with alternating conditions. Is this a common problem with a quick answer or should i post my full code?? this only happens on 2 pages with this event. I am using c# if thats of any help. net.4.5
public void topicView_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// Show or hid div here
HiddenField MediaType = (HiddenField)e.Item.FindControl("MediaType");
HiddenField PageAdmin = (HiddenField)e.Item.FindControl("PageAdmin");
HiddenField f1 = (HiddenField)e.Item.FindControl("F1");
HiddenField PP = (HiddenField)e.Item.FindControl("PP");
HiddenField isread= (HiddenField)e.Item.FindControl("isread");
HiddenField tread = (HiddenField)e.Item.FindControl("tread");
// Label Label2 = (Label)e.Item.FindControl("Label2");
// Label2.Text = myDDL.Value;
System.Web.UI.HtmlControls.HtmlContainerControl image_video = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("image_video");
System.Web.UI.HtmlControls.HtmlContainerControl image_pic = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("image_pic");
System.Web.UI.HtmlControls.HtmlContainerControl PP1 = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("PP1");
System.Web.UI.HtmlControls.HtmlContainerControl userpic = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("userpic");
System.Web.UI.HtmlControls.HtmlContainerControl compic = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("compic");
System.Web.UI.HtmlControls.HtmlContainerControl userpic2 = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("userpic2");
System.Web.UI.HtmlControls.HtmlContainerControl compic2 = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("compic2");
System.Web.UI.HtmlControls.HtmlContainerControl pf = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("pf");
System.Web.UI.HtmlControls.HtmlContainerControl attach = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("attach");
LinkButton LinkButton3 = (LinkButton)e.Item.FindControl("LinkButton3");
LinkButton LinkButton1 = (LinkButton)e.Item.FindControl("LinkButton1");
Label Label4 = (Label)e.Item.FindControl("Label4");
Label Label10 = (Label)e.Item.FindControl("Label10");
System.Web.UI.WebControls.Image readsign = (System.Web.UI.WebControls.Image)e.Item.FindControl("readsign");
System.Web.UI.WebControls.Image Image2 = (System.Web.UI.WebControls.Image)e.Item.FindControl("Image2");
if (MediaType.Value == "video")
{
image_video.Visible = false;
image_pic.Visible = true;
Image2.ImageUrl = "~/images/readmail.png";
}
if (MediaType.Value == "image")
{
image_video.Visible = true;
image_pic.Visible = false;
}
if (MediaType.Value == "" ) { attach.Visible = false; } else { attach.Visible = true; }
if (PageAdmin.Value == "False")
{
compic.Visible = false;
userpic.Visible = true;
userpic2.Visible = true;
compic2.Visible = false;
}
if (PageAdmin.Value == "True")
{
userpic.Visible = false;
compic.Visible = true;
userpic2.Visible = false;
compic2.Visible = true;
}
if (isread.Value == "True")
{
readsign.ImageUrl = "~/images/readmail.png";
Label4.Text = "foi lido ";
Label10.Text = tread.Value;
}
}
}
and my aspx code for the repeater:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"
OnItemDataBound="topicView_ItemDataBound"><ItemTemplate>
<div id="messages" style="margin-bottom: 10px">
<asp:HiddenField ID="Status" runat="server"
Value='<%#""+Eval("Isreplyed") %>' />
<asp:HiddenField ID="Pageadmin" runat="server"
Value='<%#""+Eval("PageAdmin") %>'/>
<asp:HiddenField ID="MediaType" runat="server"
Value='<%#""+Eval("MediaType") %>' />
<asp:HiddenField ID="isread" runat="server" Value='<%#""+Eval("Isread")
%>' />
<asp:HiddenField ID="tread" runat="server" Value='<%#""+Eval("tread","
{0:d / MM " + "#" + " HH:mm}") %>' />
<div id="Omsg" style="padding: 5px; border: thin solid #FFFFFF; box-
shadow:rgba(255, 255, 255,0.9) 0 0 7px; background-color: #FFFFFF;border-
radius:5px; " >
<table style="width: 100%; text-align: left; margin-left: 0px;">
<tr><td colspan="2">
<asp:Image ID="readsign" runat="server" Height="25" Width="25"
ImageUrl="~/images/newmail.png" />
<asp:Label ID="Label4" runat="server" Text='<%# ""+Eval("Isreplyed")
%>' Font-Size="X-Small" ForeColor="#999999"></asp:Label>
<asp:Label ID="Label10" runat="server" Text='<%#""+Eval("datesent","{0:d /
MM " + "#" + " HH:mm}") %>' Font-Size="X-Small" ForeColor="#999999">
</asp:Label>
</td></tr>
<tr>
<td style="width: 66px; text-align: left;"><a id="pps" ><div
id="compic" ClientIDMode="Static" runat="server"><img id="PP1" alt=""
class="img-rounded" src='<%#"/ProfilePictures/"+Eval("logo") %>'
style="width: 50px; height: 50px" /></div><input id="Hidden2" type="hidden"
runat="server" value='<%#"/ProfilePictures/"+Eval("logo") %>' /></a>
<div id="userpic" clientidmode="Static" runat="server">
<img alt="" class="img-circle"
src='<%#"/ProfilePictures/"+Eval("ProfilePicture") %>' style="width: 50px;
height: 50px" />
</div><input id="Hidden3" type="hidden" runat="server"
value='<%#"/ProfilePictures/"+Eval("ProfilePicture") %>' />
</td>
<td style="line-height: 15px"> <div id="compic2"
ClientIDMode="Static" runat="server"> <a href='<%#"/Landing.aspx?
Restid="+Eval("id") %>' ><asp:Label ID="Label2" class="head" runat="server"
Text='<%# ""+Eval("name") %>' Font-Size="Medium" ForeColor="#B9A47B">
</asp:Label> </a><a/><br/>
<asp:Label ID="CName" runat="server"
Text='<%#""+Eval("slogan") %>' Font-Size="Smaller"></asp:Label>. ...</div>
<div id="userpic2" ClientIDMode="Static"
runat="server"><a href='<%#"/Landing.aspx?Restid="+Eval("Username") %>' >
<asp:Label ID="Label8" class="head" runat="server"
Text='<%#""+Eval("Username") %>' Font-Size="Large" ForeColor="#B9A47B">
</asp:Label> <a/><br/>
<asp:Label ID="Label9" runat="server"
Text='<%#""+Eval("Job") %>' Font-Size="Smaller"></asp:Label></a>
<br />
<a/>
<a href='<%#"notificationmaster.aspx?BlogId="+Eval("Blogid") %>'> <asp:Label
ID="Label5" runat="server" Text='<%# "Respondendo à publicação :
"+Eval("BlogTitle") %>' Font-Size="smaller" ForeColor="#B9A47B"></asp:Label>
</a><br/>
</div>
<a/><span style="font-size: x-small; color: #999999">
enviado : </span><asp:Label ID="Label3" runat="server"
Text='<%#""+Eval("datesent","{0:d MMMM yyyy - HH:mm}") %>' Font-Size="X-
Small" ForeColor="#999999"></asp:Label></a>
<br />
<div id="attach" ClientIDMode="Static" runat="server" >
<asp:Label ID="Label17" runat="server" Text="Esta mensagem tem anexo"
ForeColor="#999999" Font-Size="X-Small" Font-Underline="True">
</asp:Label> <img alt="" src="images/attach.png" style="width: 20px;
height: 20px" /></div>
</td>
</tr>
<tr>
<td colspan="2">
<br/>
<div id="msgbody" style="display: none">
<asp:Label ID="Label1" runat="server" Text='<%#""+Eval("mbody") %>'>
</asp:Label><br/>
<div id="image_pic" ClientIDMode="Static" runat="server" >
<asp:HiddenField ID="HiddenField1" runat="server"
Value='<%#"/PostImages/"+Eval("image") %>' />
<asp:Image ID="Image1" class="img-thumbnail" ClientIDMode="Static"
runat="server" ImageUrl='<%#"/PostImages/"+Eval("image") %>' alt="Broken"
Width="100%" />
</div>
<div id="image_video" runat="server" onclick="AddView" >
<video id="PostVedio" runat="server" controls
poster="/images/chimoioonline.png" src='<%#"/video/"+Eval("video") %>'
style="width: 100%">
<source src="demo.mp4" type="video/mp4" />
<source src="demo.webm" type="video/webm"/>
<source src="demo.ogv" type="video/ogg"/>
<source src="demo.ogv" type="video/avi"/>
<p>Fallback code if video isn't supported</p>/
</video></div></div>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: right">
<hr style="padding: 2px; margin: 5px" />
<div id="deletm" style="display: inline-block">
<input id="Hidden1" type="hidden" runat="server"
value='<%#Eval("id")%>' />
<asp:LinkButton ID="LinkButton3" runat="server" CssClass="btn"
onclick="pmdelet" BorderColor="#CCCCCC" BorderWidth="1px"><img
src="/images/delete.png" alt="" style=" height: 15px" />
</asp:LinkButton> <br />
</div>
<div id="sendpm" style="display: inline-block">
<input id="mido" type="hidden" runat="server"
value='<%#Eval("id")%>' />
<input id="Hidden4" type="hidden" runat="server"
value='<%#Eval("BlogId")%>' />
<input id="sender2" type="hidden" runat="server"
value='<%#Eval("sender")%>' />
<asp:LinkButton ID="LinkButton1" runat="server" CssClass="btn"
BorderColor="#CCCCCC" BorderWidth="1px" OnClientClick=""
PostBackUrl='<%#"PMS.aspx?id=" + Eval("id") + "&BlogId=" + Eval("BlogId")+
"&sender=" + Eval("sender")%>' ><img src="images/pvtemail.png" alt=""
style=" height: 15px" /></asp:LinkButton>
</div>
<div id="read" style="display: inline-block">
<input id="H5" type="hidden" runat="server"
value='<%#Eval("id")%>' />
<input id="H7" type="hidden" runat="server"
value='<%#"/ProfilePictures/"+Eval("logo") %>' />
<input id="H8" type="hidden" runat="server"
value='<%#"/ProfilePictures/"+Eval("ProfilePicture") %>' />
<input id="H6" type="hidden" runat="server"
value='<%#Eval("Isreplyed")%>' />
<input id="H14" type="hidden" runat="server"
value='<%#Eval("Username")%>' />
<input id="H10" type="hidden" runat="server"
value='<%#Eval("name")%>' />
<input id="H13" type="hidden" runat="server"
value='<%#Eval("Subject")%>' />
<input id="H9" type="hidden" runat="server"
value='<%#Eval("BlogTitle")%>' />
<input id="H11" type="hidden" runat="server"
value='<%#Eval("datesent","{0:d / MM " + "#" + " HH:mm}")%>' />
<input id="H12" type="hidden" runat="server"
value='<%#Eval("mbody")%>' />
<input id="v5" type="hidden" runat="server" value='<%#
Eval("video")%>' />
<input id="p5" type="hidden" runat="server"
value='<%#Eval("image")%>' />
<input id="sender" type="hidden" runat="server"
value='<%#Eval("sender")%>' />
<input id="Hidden5" type="hidden" runat="server"
value='<%#Eval("Blogid")%>' />
<input id="PageAdmin2" type="hidden" runat="server"
value='<%#Eval("PageAdmin")%>' />
<asp:LinkButton ID="LinkButton2" runat="server" CssClass="btn"
BorderColor="#CCCCCC" BorderWidth="1px" OnClientClick="return false"><img
src="/images/read2.png" alt="" style=" height:15px" /></asp:LinkButton>
</div>
</td>
</tr>
</table>
</div>
<div id="Rmsg">
</div>
</div>
</ItemTemplate></asp:Repeater>
My Server profiler screen shot

This is not really an answer, but more a way for you to delve deeper into whats the problem. (And it's to long for a comment)
First of all you need to make sure you have SQL server managment tools installed, in particular you need the tool called SQL server profiler.
In profiler you go to "file" "new trace" and connect to you SQL server.
In the Trace properties you select only "RPC:completed" and "SQL:BatchCompleted".
Now you can run your aspx page, and you should se all SQL queries generated by the page in the profiler. There are two things you should look out for.
First of all, look for long running queries. The duration column is in MS and you should not have anyone longer than 1000ms.
Secondly, the number of queries run when the page is run. A normal page should not exceed 20 queries. Usualy when you get problems with this, you could run hundreds.

Related

asp.net imagebutton access in listview

How can i change imageUrl in listview function. I tried some codes but not worked.
my codes
protected void DoTheCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "Button")
{
ImageButton img = (ImageButton)e.Item.FindControl("Button1");
img.ImageUrl = "/img/heartcirc.png";
html code
<asp:ListView ID="listUrunler" OnItemCommand="DoTheCommand" runat="server">
<ItemTemplate>
<div class="col-lg-3 col-md-6 mb-4 mb-lg-0">
<div class=" card-img-top rounded shadow-sm border-0">
<asp:ImageButton ID="ImageButton1" class="card-img" runat="server" ImageUrl='<%# Eval("urunResim") %>' PostBackUrl='<%# String.Format("UrunDetay.aspx?Id={0}",Eval("Id")) %>' />
<div class="card-body p-4">
<h5 class="card-title" style="margin-top: -20px"><%# Eval("urunBaslik") %></h5>
<div class="price text-success" style="justify-content: center; float: left;"><%# Eval("urunFiyat") %>TL</div>
<asp:ImageButton ID="Button1" runat="server" Width="20px" Height="20px" ImageUrl="/img/heart.png" CommandName="Button" CommandArgument='<%# Eval("Id") %>' Text="Add to Cart" />
<div style="clear: both;"></div>
</div>
</div>
</div>
</ItemTemplate>
</asp:ListView>
Thanks for helps.

Is there is a way to apply css descendant combinator in asp.net labels

.box
{
font-family:'Verdana';
margin:0;
padding:0;
top:50%;
left:50%;
transform:translate(-50%,-50%);
width:400px;
position:absolute;
padding:40px;
box-sizing:border-box;
box-shadow:0 5px 10px rgba(0,0,0,.7);
border:1px solid rgba(0,0,0,.1);
font-size:15px;
}
.InputType
{
font-family:'Verdana';
padding:10px 0;
margin-bottom:30px;
width:100%;
box-sizing:border-box;
box-shadow:none;
outline:none;
border:none;
border-bottom:2px solid rgb(44, 128, 35);
}
.Labelll
{
font-size:25px;
font-family:'Verdana';
}
.Submit
{
border:none;
cursor:pointer;
background:rgb(44, 128, 35);
color:#FFFFFF;
margin-bottom:5px;
width:100%;
padding:10px 10px 10px 10px;
font-size:15px;
font-family:'Verdana';
}
.Message
{
font-size:12px;
font-family:'Verdana';
}
a,a:visited,a:active,a:hover
{
color:rgb(44, 128, 35);
font-family:'Verdana';
}
<div class="box" >
<asp:Label ID="Labell" runat="server" Text="Sign Up" CssClass="Labelll"></asp:Label>
<br />
<br />
<asp:Label ID="UserName" runat="server" Text="Your Name"></asp:Label>
<br />
<asp:TextBox ID="TextUserName" runat="server" CssClass="InputType"></asp:TextBox>
<br />
<asp:Label ID="EMailId" runat="server" Text="Email Id"></asp:Label>
<br />
<asp:TextBox ID="TextEMailId" runat="server" CssClass="InputType"></asp:TextBox>
<br />
<asp:Label ID="Password" runat="server" Text="Password"></asp:Label>
<br />
<asp:TextBox ID="TextPassword" runat="server" TextMode="Password" CssClass="InputType"></asp:TextBox>
<br />
<asp:Label ID="ConfirmPassword" runat="server" Text="Confirm Password"></asp:Label>
<br />
<asp:TextBox ID="TextConfirmPassword" runat="server" TextMode="Password" CssClass="InputType"></asp:TextBox>
<br />
<asp:Button ID="SignUp" runat="server" Text="Register" CssClass="Submit"/>
<br />
<asp:Label runat="server" Text="Already registered?" CssClass="Message">
Already registered
Login
</asp:Label>
</div>
I'm learning asp.net technology and after a while I just got stuck up with the css in asp.net.Is there is any way for how to apply descendant combinators for asp.net labels and other css selectors as well as some other css properties are not working for asp.net labels so how can I do that?I have also provided the code snippets.

Textbox with textmode time, won't display data from sql database

So i did a research about textmode time but it doesn't seem to help me. My problem is when i tried to bind the data with time textmode it won't display anything I already tried removing the textmode so i can see if it can display data and it does. Here's my code in the front, hope you'll help me. Thank you in advance
<asp:Repeater runat="server" ID="rptrTRFFormItems" OnItemDataBound="rptrTRFFormItems_ItemDataBound">
<ItemTemplate>
<tr>
<td>
<asp:Label runat="server" ID="No" Text='<%# Container.ItemIndex + 1 %>' Visible="false">
</asp:Label>
</td>
<td>
<asp:LinkButton runat="server" ID="btnAddItemRow" CssClass="actionbtnstyle fa fa-plus-square" CausesValidation="false" OnClick="btnAddItemRows" Style="font-size: 20px;">
</asp:LinkButton>
</td>
<td>
<asp:LinkButton runat="server" ID="btnDeleteItemRow" CssClass="actionbtnstyle fa fa-minus-square" CausesValidation="false" OnClick="btnDeleteItemRows" Style="font-size: 20px;">
</asp:LinkButton>
</td>
<td>
<div runat="server" id="divInputGroup">
<span runat="server" id="spanInputGroup">
<asp:Label runat="server" ID="validatetbName">
</asp:Label>
</span>
<asp:TextBox runat="server" ID="tbName" Text='<%#Eval("Name") %>' CssClass="form-control rptrtbstyle" ondrop="return false" title="Required" data-toggle="tooltip" TabIndex="13" data-placement="bottom">
</asp:TextBox>
</div>
</td>
<td>
<asp:UpdatePanel runat="server" ID="rptriddate" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="tbDate" EventName="TextChanged" />
</Triggers>
<ContentTemplate>
<div runat="server" id="divInputGroup0">
<span runat="server" id="spanInputGroup0">
<asp:Label runat="server" ID="validatetbDate">
</asp:Label>
</span>
<asp:TextBox runat="server" ID="tbDate" CssClass="form-control js-datepicker rptrtbstyle" Style="cursor: pointer;" TabIndex="14" data-toggle="tooltip" data-placement="bottom" title="Required" OnTextChanged="tbDate_TextChanged" autocomplete="off" AutoPostBack="true">
</asp:TextBox>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td>
<div runat="server" id="divInputGroup2">
<span runat="server" id="spanInputGroup2">
<asp:Label runat="server" ID="validatetbPreferredTime">
</asp:Label>
</span>
<asp:TextBox runat="server" ID="tbPreferredTime" Text='<%#Eval("PreferredTime") %>' format="HH:mm" TextMode="Time" CssClass="form-control rptrtbstyle" data-toggle="tooltip" TabIndex="15" data-placement="bottom" title="Required">
</asp:TextBox>
</div>
</td>
<td>
<div runat="server" id="divInputGroup1">
<span runat="server" id="spanInputGroup1">
<asp:Label runat="server" ID="validatetbFromRptr">
</asp:Label>
</span>
<asp:TextBox runat="server" ID="tbFromRptr" Text='<%#Eval("FromRptr") %>' CssClass="form-control rptrtbstyle" data-toggle="tooltip" data-placement="bottom" TabIndex="16" title="Required" AutoPostBack="false">
</asp:TextBox>
</div>
</td>
<td>
<asp:LinkButton runat="server" ID="btnExchange" CssClass="actionbtnstyle fa fa-exchange" CausesValidation="false" Style="font-size: 20px;">
</asp:LinkButton>
</td>
<td>
<div runat="server" id="divInputGroup3">
<span runat="server" id="spanInputGroup3">
<asp:Label runat="server" ID="validatetbToRptr">
</asp:Label>
</span>
<asp:TextBox runat="server" ID="tbToRptr" Text='<%#Eval("ToRptr") %>' CssClass="form-control rptrtbstyle" TabIndex="17" data-toggle="tooltip" data-placement="bottom" title="Required">
</asp:TextBox>
</div>
</td>
</tr>
<%--</ContentTemplate> </asp:UpdatePanel>--%>
</ItemTemplate>
</asp:Repeater>
And here's the code to bind data from behind.
using(SqlConnection con = new SqlConnection(travelrequest))
{
using(SqlCommand cmd = con.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "TRFSearchByRefernce";
cmd.Parameters.AddWithValue("#trfNo", txtSearchByReference.Text);
cmd.Parameters.AddWithValue("#fullname", lblFullname01.Text);
using(SqlDataAdapter adp = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
adp.Fill(dt);
if(dt.Rows.Count > 0)
{
rptrTRFFormItems.DataSource = dt;
rptrTRFFormItems.DataBind();
ViewState["CurrentTable"] = dt;
}
else
{
SetInitialRow();
}
}
}
}
and here's my stored procedure sql query
SELECT
[TRFGName] as Name
,[TRFGDate] as [Date]
,[TRFGTimeRef] as PreferredTime
,[TRFGFrom] as FromRptr
,[TRFGTo] as ToRptr
,[TRFGNo]
,[TRFGControlNo]
,[TRFRequester]
FROM [TRAVELREQUESTFORM].[TRAVEL].[TRAVELGRID] WHERE TRFGControlNo = #trfNo and TRFRequester = #fullname

OnChanged even't isn't firing (AJAX raiting control) inside a datalist

I'm using the latest ajax toolkit version. I've tried to put the rating control in a datalist, but the OnChanged event for some reason isn't firing.
That's the normal ASPX.NET page:
<asp:DataList ID="DataListEpisodes" runat="server" Style="position: relative; bottom: 330px;" Visible="False" RepeatColumns="1" OnItemDataBound="DataListEpisodes_ItemDataBound" DataKeyField="EpisodeID" OnItemCommand="DataListEpisodes_ItemCommand">
<ItemTemplate>
<table>
<tr>
<td>
<td>
<asp:Image ID="ImageEpisodeImage" class="EpisodeImage" runat="server" ImageUrl='<%# Eval("EpisodeImage", "https://image.tmdb.org/t/p/original{0}") %>' />
</td>
</td>
<td>
<asp:Label ID="LabelEpisodeNumber" runat="server" Style="font-family: Gotham Ultra; font-size: 25px; font-weight: bold;"
Text='<%# Eval("SeasonNumber", "Season {0}") + ", " + Eval ("EpisodeNumber", "Episode {0}") %>'></asp:Label>
<br />
<asp:Label ID="LabelEpisodeName" Style="font-family: Proxima Nova Semibold; font-size: 20px; font-weight: bold;" runat="server" Text='<%# Bind("EpisodeName") %>'></asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="True" class="LabelOverview" Text='<%# Bind("EpisodeOverview") %>' TextMode="MultiLine"></asp:TextBox>
<br />
<asp:Button ID="ButtonAddEpisode" class="ButtonAddEpisode" runat="server" Text="Add Episode To Watch History" CommandName="AddEpisode" />
<asp:Button ID="ButtonRemoveEpisode" class="ButtonAddEpisode" runat="server" Text="Remove Episode From Watch History" CommandName="RemoveEpisode" />
<br />
<asp:Button ID="ButtonWatchListAdd" class="ButtonEpisodeWatchList" runat="server" Text="Add Episode To Future Watch List" CommandName="AddWatchList" />
**<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<ajaxToolkit:Rating ID="Rating1" OnChanged="OnRatingChanged" style="position: relative;right: 301px;top: 16px;" AutoPostBack="true" runat="server"
StarCssClass="Star" EmptyStarCssClass="Star"
FilledStarCssClass="FilledStar" WaitingStarCssClass="Star">
</ajaxToolkit:Rating>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Rating1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>**
</tr>
</table>
<br />
<br />
<br />
<br />
</ItemTemplate>
</asp:DataList>
and that's the codebehind:
protected void OnRatingChanged(object sender, AjaxControlToolkit.RatingEventArgs e)
{
int rowIndex = ((sender as AjaxControlToolkit.Rating).NamingContainer as DataListItem).ItemIndex;
int RatingChosed = Rating1.CurrentRating;
int EpisodeID = Convert.ToInt32(DataListEpisodes.DataKeys[rowIndex].ToString());
}
Thank you if someone can help me :D

Get modal popup values in gridview row textbox

I have a gridview with dynamic controls. Resource name is something that I am picking up from Active directory. Search filter works in a way where you have to enter lastname, firstname and onlclick of lookup it will search. If there are more than one record a modalpopup will be displayed with dropdownlist with options to select from.
The issue is that I am unable to get the dropdown values populated into textbox present in gridview. I need this dropdown value in correct selected row's textbox.
Code behind:
protected void gvProjectResource_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Lookup")
{
GridViewRow clickedRow = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow;
TextBox t2 = ((TextBox)clickedRow.FindControl("t2"));
DataTable dt = globalObj.FindPersons(t2.Text.Split(',')[0].Trim(), t2.Text.Split(',')[1].Trim());
if (dt.Rows.Count > 1)
{
mpFindPerson.Show();
ddlPersons.Items.Clear();
ddlPersons.Items.Add(new ListItem { Value = "0", Text = "-Select User-" });
ddlPersons.DataSource = dt;
dt.Columns.Add("FullName", typeof(string), "DisplayName + ' | ' + MSID");
ddlPersons.DataTextField = "FullName";
ddlPersons.DataValueField = "MSID";
ddlPersons.DataBind();
}
else
{
t2.Text = dt.Rows[0].ItemArray[0].ToString();
}
}
if (e.CommandName == "Del")
{
}
}
protected void btnSelectPerson_Click(object sender, EventArgs e)
{
TextBox t2 = (gvProjectResource.SelectedRow.FindControl("t2") as TextBox);
t2.Text = ddlPersons.SelectedItem.Text;
mpFindPerson.Hide();
}
ASPX Code:
<div id="four">
<fieldset style="border: solid; border-width: thin; height: 220px; border-color: #a8a8a8;">
<legend id="Legend11" runat="server" visible="true" style="width: auto; margin-bottom: 0px; font-size: 12px; font-weight: bold; color: #1f497d;"> Project Resources </legend>
<div style="height: 210px; overflow: auto;">
<asp:GridView ID="gvProjectResource" Width="88%" HeaderStyle-Font-Size="X-Small" CssClass="labels" runat="server"
ShowFooter="true" AutoGenerateColumns="false" Style="margin-right: auto; margin-left:7px;"
OnRowDataBound="gvProjectResource_RowDataBound"
OnRowCommand="gvProjectResource_RowCommand" >
<Columns>
<asp:TemplateField HeaderText="Role" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign="Top" ItemStyle-Width="50%">
<ItemTemplate>
<asp:Label ID="lblRole" runat="server" Text='<%# Eval("role") %>' Visible="false" />
<asp:DropDownList ID="ddlRole" Height="23px" Width="98%" runat="server" CssClass="DropDownListStyleOverview"></asp:DropDownList>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlRole2" Height="23px" Width="98%" runat="server" CssClass="DropDownListStyleOverview"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Resource Name" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign="Top" ItemStyle-Width="50%">
<ItemTemplate>
<asp:TextBox ID="t1" Height="23px" Width="98%" runat="server" ></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="t2" Height="23px" Width="68%" runat="server"></asp:TextBox>
<asp:LinkButton runat="server" Text="Lookup" CommandName="Lookup" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-VerticalAlign="Top" ItemStyle-Width="5%">
<ItemTemplate>
<asp:LinkButton runat="server" Text="Delete" CommandName="Del" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<div style="text-align: right;">
<asp:LinkButton runat="server" Text="Add New" ID="LinkButton2" CssClass="labels"></asp:LinkButton>
</div>
</div>
<asp:Button runat="server" ID="btnModalPopUpSearch" Style="display: none" />
<AjaxToolkit:ModalPopupExtender ID="mpFindPerson"
BehaviorID="mpFindPersonBehav"
runat="server"
DropShadow="true"
BackgroundCssClass="modalBackground"
PopupControlID="pnlFindPerson"
TargetControlID="btnModalPopUpSearch">
</AjaxToolkit:ModalPopupExtender>
<asp:Panel runat="Server" ID="pnlFindPerson" CssClass="modalPopup" style="position:relative;">
<div class="labels" runat="server" style="text-align:center; position:absolute; top:20%; height:10em; margin-top:auto; margin-left:20px;">
<asp:DropDownList ID="ddlPersons" runat="server" AppendDataBoundItems="true" Width="200px">
<asp:ListItem Text="-Select User-" Value="0" />
</asp:DropDownList>
<br />
<br />
<br />
<div style="text-align: center;">
<asp:Button runat="server" Font-Size="9pt" Text="Select" CssClass="buttons___" Style="float: left;"
ID="btnSelectPerson" OnClick="btnSelectPerson_Click" />
</div>
</div>
</asp:Panel>
</fieldset>
</div>
ok, so, there was nothing much to do.
have to add this.
protected void btnSelectPerson_Click(object sender, EventArgs e)
{
TextBox t2 = (TextBox)gvProjectResource.FooterRow.FindControl("t2");
t2.Text = ddlPersons.SelectedItem.Text;
mpFindPerson.Hide();
}

Categories

Resources