Category Archives: ListView

[RESOLVED] Databinding asp:calendar control

Is it possible to make asp:calendar control databindable to SQL database? Like GridView or ListView. I don't see how to do it and find it unbelievable. Or is there third party calendar control that is easy to use?

IgorB

Is it possible to make asp:calendar control databindable to SQL database?
 

What do you want to bind in calendar control? are you looking to select dates in calendar depending on SQL data? If so check DayRender Event(This event is raised when each day is created in the control hierarchy for the Calendar control.)

Ps:You may find this article useful..

http://odetocode.com/Articles/223.aspx

[RESOLVED] FindControl method doesn't work with masterpage

Hi all, i have a masterpage and other pages. i want to use findcontrol method to find a textbox (not on the master page) to check whether it is empty or not.

my code is as folows;

Dim myContentPlaceHolder As ContentPlaceHolder = CType(Master.FindControl("MainContent"), ContentPlaceHolder)

Dim UpdatePanel1 As UpdatePanel = CType(myContentPlaceHolder.FindControl("UP1"), UpdatePanel)

Any help please. 

 

Dim tmptxt As TextBox = CType(Master.FindControl("txtbox1"), TextBox)


If Not tmptxt Is Nothing Then
 'get tmptxt.Text value
End If


my textbox in not on the masterpage, it is on the default.aspx page. i tried

Dim myTextBox As TextBox = CType(Master.FindControl("TextBox1"), TextBox)  , but doesn't worked. Any more help please

i should also mention that the TextBox1 is inside listview, the listview is inside an updatepanel (updatepanel is inside a panel -ajax modalpopupextender).

Hi,

First you need to find the textbox in listview. Since I'm not sure which textbox you find in listview. Here's a example:

<asp:ListView ID="ListView1" runat="server">
            <ItemTemplate>
                <tr id="Tr2" runat="server">
                    <td align="center">
                        <asp:Label ID="lbP1" runat="Server" Text='<%#Eval("P1") %>' />
                    </td>
                    <td align="center">
                        <asp:Label ID="lbP2" runat="Server" Text='<%#Eval("P2") %>' />
                    </td>
                   

                </tr>
            </ItemTemplate>
</asp:ListView>
Protected Sub FindItems()
	Dim ctl As Control = Me.ListView1.Items(0).FindControl("lbP1")  //find textbox in the first item of ListView
End Sub

Protected Sub Button1_Click(sender As Object, e As EventArgs)
	FindItem()
End Sub


Find the child page's ListView in masterpage:

Dim panel As UpdatePanel = TryCast(Me.ContentPlaceHolder1.FindControl("UpdatePanelID"), UpdatePanel)
Dim listview As ListView = TryCast(panel.FindControl("ListViewID"), ListView)


Please notice that if the control is wrapped in a parent control, you need to first find the control from this parent control(container).

Here are some good article:

http://weblogs.asp.net/dwahlin/archive/2006/08/25/Finding-ASP.NET-Child-Controls_2E002E002E002E00_The-Simple-Way.aspx

http://www.west-wind.com/Weblog/posts/5127.aspx

Hope this can help you.
 

[RESOLVED] ImageButton OnClick cause - Invalid postback or callback argument

I have a page that uses a master page. The following code only shows the bare minimum of the page:


<asp:ListView ID="lvGalleries" runat="server">
  <LayoutTemplate>
    <table>
      <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
    </table>
  </LayoutTemplate>
  <ItemTemplate>
    <tr>
      <td>
        <asp:ImageButton OnClick="LoadGallery_Click" runat="server" ImageUrl='<%# Eval("Url") %>'  />
      </td>
    </tr>
  </ItemTemplate>
  <EmptyDataTemplate>
    <tr><td>none</td></tr>
  </EmptyDataTemplate>
</asp:ListView>




Code-behind:

protected void LoadGallery_Click(object sender, ImageClickEventArgs e) 
    {         
       //code
    }


The

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration 
or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback 
or callback events originate from the server control that originally rendered them.  
If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or 
callback data for validation.




My guess is that it may releated to the ID's that are recreated..

Change the enableEventValidation="true" in the page directive at the top of your aspx page to 'false'

 

You have to add ListView.Databind() in the Page_Load . That will take care of the expression in the imageUrl. Hope this helps

I have DataBind() in the Page_Load.

The change of enableEventValidation="true" to false works.
But the event isnt fires / I dont get to the breakpoint at the beginning of the function. 

And what does enableEventValidation="false" cause?

can you share the code with which you are binding the listview control

Did you saw my previous reply edit?

Its nested code, that execute a select steatment and return datatable. That datatable I bind to the datasource of the listview, then I do databind...

Any thoughts?

are you doing Databinding in IsPostBack Check???? that might be one of the reason for making the event validation corrupted....do databind in all page_load...try like that....

Thanks.

protected void LoadGallery_Click(object sender, ImageClickEventArgs e)
    {
      //code
 }


    protected void Page_Load(object sender, EventArgs e)
    {
        RefreshGalleries();
    }




    private void RefreshGalleries()
    {
        lvGalleries.DataSource = // call to a function that returns datatable
        lvGalleries.DataBind();
    }

this is the code i use

Can you include the code RefreshGalleries(); in If(!IsPostBack) and check what is happening....

I seriously doubt that binding everytime the listview in page_load might cause the problem....

Thanks.

Well, nothing happens. The LoadGallery_Click still isnt firing...

When you click on the link, Does it postback to the server or open the link without a postback?

<div style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; margin: 8px;" mce_style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; margin: 8px;">

I see the page reload - its meen there been a postback, I put breakpoint on the LoadGalleries_Click and it didnt get there.

The ImageButton doesnt have navigateUrl as you can see so theres no link to open.

</div>

I developed a simple example w/ ListView & imageButton ,

just very similar , what you have. This works perfect & I don't see any error.

Here it is

//aspx
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:ListView ID="lvGalleries" runat="server">
  <LayoutTemplate>
    <table>
      <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
    </table>
  </LayoutTemplate>
  <ItemTemplate>
    <tr>
      <td>
        <asp:ImageButton ID="ImageButton1" OnClick="LoadGallery_Click" runat="server" ImageUrl='<%# Eval("URL") %>'  />
      </td>
    </tr>
  </ItemTemplate>
  <EmptyDataTemplate>
    <tr><td>none</td></tr>
  </EmptyDataTemplate>
</asp:ListView>
</asp:Content>




//codebehind
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lvGalleries.DataSource = GetDT();
            lvGalleries.DataBind();
        }
    }


    private DataTable GetDT()
    {
        DataTable dtDFS = new DataTable();
        dtDFS.Columns.Add("ID");
        dtDFS.Columns.Add("URL");
        dtDFS.Columns.Add("Name");


        DataRow dr = dtDFS.NewRow();
        dr["ID"] = 1;
        dr["URL"] = "www.google.com";
        dr["Name"] = "Google";
        dtDFS.Rows.Add(dr);




        dr = dtDFS.NewRow();
        dr["ID"] = 2;
        dr["URL"] = "www.microsoft.com";
        dr["Name"] = "MS";
        dtDFS.Rows.Add(dr);


        dr = dtDFS.NewRow();
        dr["ID"] = 3;
        dr["URL"] = "www.yahoo.com";
        dr["Name"] = "yahoo";
        dtDFS.Rows.Add(dr);
        return dtDFS;
    }
    protected void LoadGallery_Click(object sender, ImageClickEventArgs e)
    {
        int r1 = 9;
    }


 

You got me wonder how this possible, so I dug into my code and saw that all this time i was click the wrong link (this page isnt design yet).

Thanks a lot and sorry for the HUGE mix up.

[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!

ListView with random selected items and DataPager

Hi,

what would be the best solution to display random items from SQL Server DB (newID()) in ListView with DataPager?

If DataPager is not an option, than what is?

Thank you.