How to pass argument in hyperLink navigateUrl inside a repeater - c#

I am working on a video portal application, I have use a html template for designing. I have use asp:Repeater control display all the video images. When a specific image is clicked the page is redirected to video detail page.
Here is my html code,
<asp:Repeater ID="rp_videos" runat="server">
<ItemTemplate>
<div class="col-md-4 col-sm-6 small-grid">
<div class="vid-img-holder wow pulse" data-wow-duration="1s">
<div class="top-shadow">
<span>'<%# Eval("time_before") %>'</span>
<span>From <i class="fa fa-youtube-play"></i></span>
<span><i class="fa fa-eye"></i>'<%# Eval("views") %>'</span>
</div>
<asp:HyperLink ID="hl_video_img" runat="server" NavigateUrl="~/Views/VideoDetail.aspx">
<asp:HiddenField ID="hf_file" runat="server" Value="'<%# Eval("file") %>'" />
<asp:Image ID="img_video_image" runat="server" class="img-responsive hidden-sm hidden-xs" ImageUrl='<%# Eval("image") %>' AlternateText="video_thumb" />
<img class="img-responsive hidden-md hidden-lg" src="../images/main-vid-image-smmd-1.jpg" alt="video_thumb" />
<span class="play-icon">
<img class="img-responsive play-svg svg" src="../images/play-button.svg" alt="play" onerror="this.src='images/play-button.png'" />
</span>
</asp:HyperLink>
<h3 class="vid-author">
<span>By '<%# Eval("publisher_name") %>'
</span>
'<%# Eval("title") %>'
</h3>
<div class="bottom-shadow"></div>
<div class="overlay-div"></div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
I want to pass the detail of a video which is clicked, here is the view of all video page.

In your hyperlink add the code in the Navigate URL (you have to use single quotes)
<asp:HyperLink ID="hl_video_img" runat="server" NavigateUrl='~/Views/VideoDetail.aspx?videoid=<%# DataBinder.Eval(Container.DataItem,"video_id")%>'>
So you generate the proper link and you pass the id of the video you want to open.
Now in your VideoDetail.aspx add the code to get the parameter from the Query String in your page_load function
if (Request.QueryString.HasKeys())
{
try
{
//get the id from query string
string videoID = Request.QueryString["videoID"].ToString();
}
catch { }
}

Related

Creating Comment box With Reply Option using Asp.Net

I am tring to Create a Comment box having reply option for my Website
Below Is My aspx page
<div>
<asp:Repeater runat="server" ID="repAnswer">
<ItemTemplate>
<h6>Answer</h6>
<p><%# Eval("Answer") %></p>
<asp:Label runat="server" ID="lblAnsId" Text='<%# Eval("AnsId")%>' Visible="false"></asp:Label>
<a class="link" id='lnkReplyParent<%#Eval("AnsId") %>' href="javascript:void(0)" onclick="showReply(<%#Eval("AnsId") %>);return false;">Reply</a>
<a class="link" id="lnkCancle" href="javascript:void(0)" onclick="closeReply(<%#Eval("AnsId") %>);return false;">Cancle</a>
<div id='divReply<%#Eval("AnsId") %>' style="display:none;">
<asp:TextBox ID="textCommentReplyParent" CssClass="input-group" runat="server" Width="300px" TextMode="MultiLine" ></asp:TextBox>
<br />
<asp:Button ID="btnReplyParent" runat="server" Text="Reply" OnClick="btnReply_Click" /></div>
</ItemTemplate>
</asp:Repeater>
</div>
<div style="margin-top:100px">
<h5>Your Answer</h5>
<hr />
<CKEditor:CKEditorControl ID="txtAddAnswer" BasePath="Admin/ckeditor/" runat="server">
</CKEditor:CKEditorControl>
<asp:Button runat="server" ID="btnAnswer" Text="Submit Answer" OnClick="btnAnswer_Click"/>
</div>
i have used Repeater to bind my answer or comment. Inside the repeater i have given two link pne is of reply other is of cancel.when someone click on the reply a new textbox and button open which is used to give the reply
Below is my cs page
protected void btnReply_Click(object sender, EventArgs e)
{
foreach (RepeaterItem row in repAnswer.Items)
{
Label lblNewAnsIdholder = (Label)row.FindControl("lblNewAnsIdholder");
TextBox txtReplyToAnswer = (TextBox)row.FindControl("txtReplyToAnswer");
OnlineSubjects onlinesub = new OnlineSubjects()
{
reply = txtReplyToAnswer.Text.Trim(),
AnsId = Convert.ToInt32(lblNewAnsIdholder.Text.ToString())
};
onlinesub.addAnswer();
}
}
i dont know how to use textbox in repeater but after searching it through google i get something like this which i am not sure thats right or wrong.
And the line where i have created my object for my class i am getting error from there
I am tring to pass the value of textbox as a paramter
Plz help me to do this.
Thank You
You Should try,
TextBox txtReplyToAnswer = ((TextBox)row.FindControl("txtReplyToAnswer")).Text;
Hope this will work.

How to Get data in repeater from multiple table using like linq query

Code Behind:
Entities db = new Entities();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindRepeater();
}
}
private void BindRepeater()
{
var q = from u in db.tbl_Question_Result
join v in db.tbl_Question on
u.Question_Id equals v.Question_Id
where u.Student_Id.Equals(1) && v.Paper_Id.Equals(5) select new {u,v};
ResultRepeater.DataSource = q.ToList();
ResultRepeater.DataBind();
}
Front End:
<asp:Repeater ID="ResultRepeater" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<div class="row show-grid">
<div class="col-md-4">
<span class="show-grid-block">
<asp:Label ID="QuestionLabel" runat="server" Text="<%# Eval("u.Question_Obtained_Marks") %>"></asp:Label>
</span>
</div>
<div class="col-md-4">
<span class="show-grid-block">
<asp:Label ID="QuestionLabel1" runat="server" Text="<%# Eval("v.Question_Total_Marks") %>"></asp:Label>
</span>
</div>
<div class="col-md-4">
<span class="show-grid-block">
<asp:Label ID="QuestionLabel2" runat="server" Text="<%# Eval("v.Question_Question") %>"></asp:Label>
</span>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
Error:
I got this error on line where i use Eval Fuction.
Parser Error
Description:An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: The server tag is not well formed.
This happens because you are not properly formatted the quotes of your controllers.
Please try change
"<%# Eval("v.Question_Question") %>"
to following
'<%# Eval("v.Question_Question") %>'
and all other places as well.

How to know which item is selected in the ListView in asp.net

I have a Listview which I have used to display messages.Along with each message there is a link to "Reply" message.Since different user can send message to one user.The user have different message from different user.Now i need to track each user who are sending message.I was wondering if there is a way to know which message is selected so that the sender's id can be traced.
Here is my List view.
<asp:ListView ID="msg_list" runat="server">
<ItemTemplate>
<table>
<tr class="myitem">
<td>
<asp:Label role="menuitem" ID="msg_lbl" runat="server" text='<%#Eval("msg")%>' /><i style=" color:Gray; " > from
<asp:Label ID="tme" runat="server" Text='<%#Eval("name")%>' />
<i> on </i>
<asp:Label ID="tmelbl" runat="server" Text='<%#Eval("tme")%>'/>
<a id="msg-reply" class="btn button" data-toggle="modal" data-target="#msg-rply" style="cursor:pointer;" ><i class="glyphicon glyphicon-share-alt white"> </i></a> </td>
<hr style=" margin-top:1px; margin-bottom:1px; " />
</tr>
</table>
<%--<hr style=" margin-top:1px; margin-bottom:1px; " />--%>
</ItemTemplate>
</asp:ListView>
With this list view i display the messages.In the above code you can see this line <a id="msg-reply" class="btn button" data-toggle="modal" data-target="#msg-rply" style="cursor:pointer;" ><i class="glyphicon glyphicon-share-alt white"> </i></a> </td>
So,when I click the icon a lightbox appears(modal of bootstrap) where i can write my message.
This lightbox has a button to send message(insert to database) which is as follows.
public void reply_msg(object sender, EventArgs e)
{
string tym = DateTime.Now.ToString();
string sid = Session["userid"].ToString();
//string rid = ((Label)msg_list.FindControl("easy")).Text;
//Label mr = (Label)msg_list.FindControl("reg_id_reply");
// string rid = mr.Text;
string rid = Session["msgreply"].ToString();
//msg_list.Items.FindControl("easy");
sc.connection();
SqlCommand cmd = new SqlCommand("insert into message(msg,senderId,receiverId,tme) values( #msg,#sid,#rid,#tme) ", sc.con);
cmd.Parameters.AddWithValue("#msg", ReplyMsgTb.Text);
cmd.Parameters.AddWithValue("#sid", sid);
cmd.Parameters.AddWithValue("#rid", rid);
cmd.Parameters.AddWithValue("#tme", tym);
cmd.ExecuteNonQuery();
sc.con.Dispose();
sc.con.Close();
}
What i need is to know which item of ListView is selected when i click the icon that brings out the lightbox to send message.
OR is there any other way to know which item of Listview is selected.
You can use check box with every row. So when the user checks the check box for the particular row you can easily reply to the selected user.
your code will be something like this:-
<asp:ListView ID="msg_list" runat="server">
<ItemTemplate>
<table>
<tr class="myitem">
<td>
<asp:TemplateField HeaderText="Id" ItemStyle-HorizontalAlign="Left">
<ItemTemplate >
<asp:CheckBox ID="chkRow" onclick ="CheckSingleCheckbox(this)" AutoPostBack="true" runat="server" OnCheckedChanged="chkRow_CheckedChanged"/>
</ItemTemplate>
</asp:TemplateField>
<asp:Label role="menuitem" ID="msg_lbl" runat="server" text='<%#Eval("msg")%>' /><i style=" color:Gray; " > from
<asp:Label ID="tme" runat="server" Text='<%#Eval("name")%>' />
<i> on </i>
<asp:Label ID="tmelbl" runat="server" Text='<%#Eval("tme")%>'/>
<a id="msg-reply" class="btn button" data-toggle="modal" data-target="#msg-rply" style="cursor:pointer;" ><i class="glyphicon glyphicon-share-alt white"> </i></a> </td>
<hr style=" margin-top:1px; margin-bottom:1px; " />
</tr>
</table>
<%--<hr style=" margin-top:1px; margin-bottom:1px; " />--%>
you can use the script given below for finding which check box has been checked:-
<script type="text/javascript">
function CheckSingleCheckbox(ob) {
var grid = ob.parentNode.parentNode.parentNode;
var inputs = grid.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
if (ob.checked && inputs[i] != ob && inputs[i].checked) {
inputs[i].checked = false;
}
}
}
}
</script>

Switch Ajax Tabs in TabContainer by Tab ID

I have an ajax control toolkit TabContainer. The active tab is controlled using c# in the following manner below. I have many tabs on my tabcontainer.
Is it possible to switch tabs by referencing the tab ID in C# as opposed to the number of the tab?
c#
TabContainerMain.ActiveTabIndex = 5;
HTML
<asp:TabContainer ID="TabContainerMain" runat="server" ActiveTabIndex="4" Width="100%"
Height="100%" CssClass="" ViewStateMode="Enabled">
<asp:TabPanel runat="server" HeaderText="Tab_Monitor" ID="Tab_Monitor">
</asp:TabPanel>
<asp:TabPanel ID="Tab_Remove_Item" runat="server" HeaderText="Tab_Remove_Item">
<ContentTemplate>
<div class="TabControls">
<p>
Howdy, I'm in Section Tab_Remove_Item .</p>
</div>
<div class="TabsAction">
</div>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="Tab_2nd_Sign_System" runat="server" HeaderText="Tab_2nd_Sign_System">
<ContentTemplate>
<div class="TabControls">
<p>
Howdy, I'm in Section Tab_2nd_Sign_System .</p>
</div>
<div class="TabsAction">
</div>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="Tab_Configure_Device" runat="server" HeaderText="Tab_Configure_Device">
<ContentTemplate>
<div class="TabControls">
<p>
Howdy, I'm in Section Tab_Configure_Device .</p>
</div>
<div class="TabsAction">
</div>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
Yes, you can use the ActiveTab property. For example:
get
if(TabContainerMain.ActiveTab == this.Tab_Remove_Item)
{
// ...
}
set
TabContainerMain.ActiveTab = this.Tab_2nd_Sign_System;
If you only have the ID as string, you can use LINQ (or a loop) to get the reference:
String tabPanelID = "Tab_Remove_Item";
TabContainerMain.ActiveTab = TabContainerMain.Tabs
.Cast<AjaxControlToolkit.TabPanel>()
.First(t => t.ID == tabPanelID);

UpdatePanel, ModalPopupExtender, and enter keypress issues

Have an UpdatePanel that contains 2 panels with default buttons set to listen to enter key presses. That UpdatePanel is the PopupControl for a ModalPopupExtender.
Running into an issue when pressing enter in the modal popup in which the entire page posts back. Any ideas? Here are some code snippets (I've removed the extraneous fields...):
<div runat="server" id="divShippingEstimatorPopup" class="shippingEstimatorModalPopup">
<asp:UpdatePanel ID="upPopup" runat="server">
<ContentTemplate>
<asp:Panel runat="server" ID="pnlShippingEstimator" DefaultButton="lnkbtnGetEstimates">
<div class="title content_title">Shipping Estimator</div>
<asp:Label runat="server" ID="lblMessage" />
<table cellpadding="0" cellpadding="0" class="shipping">
<!-- Removed to shorten code snippet -->
<tr>
<td colspan="2">
<div class="buttonHolder">
<Monarch:LinkButtonDefault runat="server" ID="lnkbtnGetEstimates" CssClass="button_action button_margin_right" CausesValidation="false">Get Estimates</Monarch:LinkButtonDefault>
<asp:LinkButton runat="server" ID="lnkbtnCancel" CssClass="button_secondary button_secondary_fixed" CausesValidation="false">Cancel</asp:LinkButton>
<div class="clear"></div>
</div>
<div class="clear"></div>
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel runat="server" ID="pnlShippingOptions" DefaultButton="lnkbtnSetEstimate">
<div class="shippingOptionsHolder" runat="server" id="divShippingOptionsHolder">
<!-- Removed to shorten code snippet -->
<div class="buttonHolder">
<Monarch:LinkButtonDefault runat="server" ID="lnkbtnSetEstimate" CssClass="button_action">Set Estimate</Monarch:LinkButtonDefault>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Keep in mind the LinkButtonDefault is just this:
public class LinkButtonDefault : LinkButton
{
private const string AddClickScript = "SparkPlugs.FixLinkButton('{0}');";
protected override void OnLoad(EventArgs e)
{
string script = String.Format(AddClickScript, ClientID);
Page.ClientScript.RegisterStartupScript(GetType(), "click_" + ClientID,
script, true);
base.OnLoad(e);
}
}
Finally, here is the rest of the control:
<asp:UpdatePanel runat="server" ID="upGetEstimate">
<ContentTemplate>
<asp:LinkButton runat="server" ID="lnkbtnGetEstimate" CausesValidation="false">Get Estimate</asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
<ajaxToolKit:ModalPopupExtender ID="shippingEstimatorPopupExtender" runat="server" TargetControlID="lnkbtnFake" PopupControlID="divShippingEstimatorPopup" BackgroundCssClass="monarchModalBackground"></ajaxToolKit:ModalPopupExtender>
<asp:LinkButton runat="server" ID="lnkbtnFake" style="display:none;"/>
<Monarch:PopupProgress ID="popupProgressGetEstimate" runat="server" AssociatedUpdatePanelId="upGetEstimate" />
<Monarch:PopupProgress ID="popupProgressGetEstimates" runat="server" AssociatedUpdatePanelId="upPopup" />
Basically, the user clicks Get Estimate, a progress bar appears while it loads the form, the form shows in a modal popup. I'm guessing this is something simple, but I can't just get the right combination to get this working properly.
First of all try what happens if you use your scriptmanager to register script in the code behind.
I use this method for registering scripts:
public static void RegisterStartupScript(Control c, string script)
{
if ((ToolkitScriptManager.GetCurrent(c.Page) as ToolkitScriptManager).IsInAsyncPostBack)
ToolkitScriptManager.RegisterStartupScript(c, c.GetType(), "Script_" + c.ClientID.ToString(), script, true);
else
c.Page.ClientScript.RegisterStartupScript(c.GetType(), c.ClientID, script, true);
}
This checks if you have ScriptManager in your page. If it doesn't, it uses the full postback version.

Categories

Resources