Category Archives: Repeater

[RESOLVED] HTML Encoding in an asp:LinkButton

Hey All

I am trying to use HTML Encoding in an asp:LinkButton, but it is not working for me. Here is my code:

<% foreach (var id in item.DataID)
	 { %>
		<asp:LinkButton runat="server" ID="DailyUnitValueHyperLink"
					Text="Daily Trends"
					onclick="DailyUnitValueHyperLink_Click"
					CommandArgument="<%: id %>"></asp:LinkButton>
   <% } %>


I am getting the DataId from list of string on my page Model. I am then trying to place that ID into the CommandArgument of the LinkButton. But it is not working.

I have tried both of these and neither work:

I don't think a code block like this can work.   You're trying to create multiple LinkButtons, all with the same ID, and ID's are required to be unique.

I suggest using a Repeater to handle this.

http://www.w3schools.com/ASPNET/aspnet_repeater.asp 

[RESOLVED] call the code begind method in a aspx page

hello,

       how can we call the code begind method in a aspx page?

for ex:

code behind:

==========

public bool sample()
        {
            return true;
        }

 

aspx:

===========

<asp:CheckBox ID="chkPFCeilingFlag" runat="server" TabIndex="15" Checked='<%# sample() %>'
Enabled="true" CssClass="CheckBox"></asp:CheckBox>

but it is not called.

 

hi,

 this.chkPFCeilingFlag.DataBind();

 bcos this '<%# sample() %>' code will be executed while calling databind()

Hello,


You can set the Checked property of CheckBox on PageLoad event like this:

<asp:CheckBox ID="chkPFCeilingFlag" runat="server" TabIndex="15" Enabled="true" CssClass="CheckBox"></asp:CheckBox>


<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        If Not Page.IsPostBack Then</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            chkPFCeilingFlag.Checked = sample()</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        End If</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">    End Sub</div>

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!Page.IsPostBack)

        { 

              chkPFCeilingFlag.Checked = sample();

        }

    }


Please mark as Answer if it helps you.....Nitesh Garg

As the two people above me have stated, when you use <%# %>, it will perform these actions on the databinding event for the containing control.

I don't see why you would actually want to do it like this and not in the code behind, as this just seems to be a sloppy method to achieve whatever it is that you want.

Seeing as this isn't a dynamic control inside a template for a gridview/dataview/... you should probably just set the value in the page_load event.

you have to call chkPFCeilingFlag.DataBind() in page Load event

thanks


As per looking your code I dont understand what is the requiremet to write this kind of code in aspx page that you can achieve easily by writing it in page_load event.

 

But anyways...  Checked='<%# sample() %>' this want works to achieve from aspx page you can do it from javascript by following code.

function AlertMessage() {


            if ('<%=sample() %>' == 'True');
            {
               document.getElementById('chkPFCeilingFlag').checked = 1;
                

            }
        }


After that you need to call this function after in your page but make sure call this function in after your control load mean write this function exection code after the checkbox conrols aspx code (by line no)

 

Mark as answer if this answer for your question

nice.it is worked.if that function is in another one class then how can we call it.


If your current problem has been solved, mark the thread as resolved or mark the post as an answer. Start a new thread for new question.

The javascript method is not the best approach, as you know what you want to render, and it won't work is javascript is turned of.

server controls (those with a runat=server) only support binding expressions. if you want to use binding expressions, for a page where the controls are not in a repeater, etc, in page load you can just call:

  Page.DataBind();

if you want more control, (say you have a repeater), just wrap the controls you want to databind, in a panel, then call databind() on the panel in page load.

  pnlName.DataBind();

of course you could just call databind on the one control.

 cntName.DataBind()

and any expressions on it will work.


[RESOLVED] paging

I have a webpage where I am adding UserControls on the fly depending upon number of rows in a dataset. row data feeds the usercontrol.

I want to add paging if number of usercontrols is more that 5, which in turn means if number of rows in the dataset is more than 5. It is like this forum where it pages based upon number of replies to a post.  

Any best practices?

yeah, this could be one option. I am looking for a more elegant solution. I don't want to use dropdowns for page navigation.

 

If I am not wrong then you have created one use controls for displying set of item just like one row and you are adding that contrils to show list of data (as no of rows) and now you want to establish paging for this functionality.

 

Then you can use datagird, gridview or repeater cotrol and add you user contorl in itemtemplate of dataview. 

<asp:TemplateField HeaderText="<%$ Resources:KHResource, Actions %>" >
    <ItemTemplate>
        <uc1:MyControl ID="rowMyControl" runat="server" />
         </ItemTemplate>
     <ItemStyle HorizontalAlign="Center" Width="30px" />
</asp:TemplateField>


for Paging you can set avalalbel paging for your grid view controls. no need to extra things to implement

 

Mark as answered if this is helps 

 

I need to set some properties of User Control from row data. Please suggest if this is possible with this approach. 

Hi, You can try like this .... I have used this for repeater ..you can use this for some other control alsp ...have a look ...


SqlDataAdapter da = new SqlDataAdapter(sqlstring, connection);
        DataSet ds = new DataSet();
        da.Fill(ds, "image_data");
        PagedDataSource pageds = new PagedDataSource();
        pageds.DataSource = ds.Tables["image_data"].DefaultView;
        pageds.AllowPaging = true;
        pageds.PageSize = 5;
        int curpage = 0;

        if ((Request.QueryString["Page"] != null))
        {
            curpage = Convert.ToInt32(Request.QueryString["Page"]);
        }
        else
        {
            curpage = 1;
        }

        pageds.CurrentPageIndex = curpage - 1;
        lblCurrpage.Text = "Page: " + curpage.ToString();

        if (!pageds.IsFirstPage)
        {
            lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curpage - 1);
        }

        if (!pageds.IsLastPage)
        {
            lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curpage + 1);
        }

        Repeater1.DataSource = pageds;

        Repeater1.DataBind();

Hi vaibhav, I am able to set the properties too in the template field method. Thanks for the inputs.  

[RESOLVED] RadioButtonList inside parent RadioButtonList

I am writing a form which has a set of options (radio buttons), and under each option, there is another set of options.  For example:

 - Session 1

      - New Book A

      - Used Book A

- Session 2

      - New Book B

      - Used Book B

I've tried using HTML <input type="radio", and <asp:RadioButton, but even though I assign the "name" attribute correctly, the buttons are not mutually exclusive -- i.e., you can click both within each group.  I see in "View Source" that the name and ID are altered, and therefore become ungrouped by the ASP.NET processing.

I've tried using <asp:RadioButtonList, and this works functionally, but the items are not grouped properly.  They appear like this:

- Session 1

- Session 2

      - New Book A

      - Used Book A

      - New Book B

      - Used Book B

I have not been able to find a solution to this problem, and would appreciate any help...

Thank you for responding.  The link you provided says, "Based on my research and experience, I think that it is impossible tocreate "nested radio button lists" using VS.NET"...

niksv

 http://bytes.com/topic/asp-net/answers/290891-nested-radiobuttonlists
 

I'm beginning to believe this, but it seems incredible to me that ASP.NET web forms cannot handle this.  I know this can be done with classic ASP (because I am converting an old web app which does this).  It also uses javascript to select the parent button if a child option is selected.  I will keep trying, and will post my result.


Please try this

//aspx
<form id="form1" runat="server">
    <div>
    

    </div>
    <br />
    <span>XXXXXXX</span>
    <br />
    <input id="RadioButtonList2_0" type="radio" name="RadioButtonList2" value="A" /><label for="RadioButtonList2_0">AAA</label>
    <br />
    <input id="Radio1" type="radio" name="RadioButtonList2" value="B" /><label for="RadioButtonList2_0">BBb</label>
    <br />
    <input id="Radio2" type="radio" name="RadioButtonList2" value="C" /><label for="RadioButtonList2_0">ccc</label>
    <br />
    <span>ZZZZZZZZ</span>
    <br />
    <input id="Radio3" type="radio" name="RadioButtonList2" value="D" /><label for="RadioButtonList2_0">ddd</label>
    <br />
    <input id="Radio4" type="radio" name="RadioButtonList2" value="E" /><label for="RadioButtonList2_0">eee</label>
    <br />
    <input id="Radio5" type="radio" name="RadioButtonList2" value="F" /><label for="RadioButtonList2_0">ffff</label>




    

    </form>


 

Thank you, but it's not really what I'm looking for.  I would like to put the parent radio buttons where you have the XXXXXXX and ZZZZZZZ text.  Also, I need to databind the parent radio buttons first.  When each parent item is created, I need to databind the corresponding child radio buttons based on a datakey from the parent datasource.


I could easily do something similar using ListViews, for example, using the parent ListView's ItemDataBound event to create a child ListView, but RadioButtonList does not have something like ItemDataBound.


I tried doing this using nested ListViews, and creating the individual radio buttons as HTML or ASP.NET server controls as described in my original post, but that (surprisingly) doesn't work because the "name" (HTML) or "GroupName" values I assign are not retained, and even though the page renders as I would like it to look, the radio buttons become ungrouped and useless.

Please refer this ([decker dong - msft]'s answer)  workaround here , for a similar situation like yours.

http://forums.asp.net/t/1458411.aspx

Hope this helps. 

Thank you, that does work for the scenario I posted.  

Unfortunately, I simplified my problem for posting, and ultimately, I need to place these radio buttons within a Repeater or ListView to produce additional layers and perform addition event handling.  I finally found that there is actually a bug in ASP.NET (http://support.microsoft.com/kb/316495) which prevents radio buttons from being mutually exclusive when used within a Repeater or ListView.  I've looked for a solution or workaround, but have not found one.  If you know of any, please let me know.  I am also going to ask for this in a new and separate thread.

Thanks again for your help!