Pass radio button Value into DataSource Method of Repeater

Last post 07-07-2009 8:40 AM by kramer9802. 2 replies.

Sort Posts:

  • Pass radio button Value into DataSource Method of Repeater

    06-30-2009, 12:02 PM
    • Member
      point Member
    • kramer9802
    • Member since 06-30-2009, 11:50 AM
    • Posts 2

    I am using ASP .Net 2.0 with VB. I have a page with 4 radio buttons, a grid and a repeater and a gridview inside the repeater. Right now the gridview inside the repeater uses a field from the first grid to pass into the data source.

       
         <asp:GridView ID="gvWaterLevels" AutoGenerateColumns='false' runat="Server"
                          DataSource='<%# GetWaterLevels(CType(Eval("strSiteId"), string)) %>'>


    What I need to do is evaluate the Radio buttons in a javascript and pass the return of the JavaScript to the method GetWaterLevels(); or Somehow figure out which radio button is selected and pass it to the GetWaterlevels() method


    Here is the Javascript.

    function TimePeriod()
    {
        var rbPeriod = document.getElementById("rbPeriod");
        var rbfive= document.getElementById("rbfive");
        var rbTen = document.getElementById("rbTen");
        var rbFifteen = document.getElementById("rbFifteen");
        var rbTwenty = document.getElementById("rbTwenty");
        
        if (rbPeriod.Checked)
        {
        Return 0;
        }
        if (rbfive.Checked)
        {
        Return 5;
        }
        if (rbTen.Checked)
        {
        Return 10;
        }
        if (rbFifteen.Checked)
        {
        Return 15;
        }
        if (rbTwenty.Checked)
        {
        Return 20;
        }
    }

    Please Let me know my other options. Is there a CodeBehind way to Set Repeater Datasource from the first grid?
  • Re: Pass radio button Value into DataSource Method of Repeater

    07-05-2009, 11:40 PM
    Answer

    Hi kramer9802,

    You can handle ItemDataBound event of Repeater to pass value to the function.

    Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
        If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim gv As GridView = DirectCast(e.Item.FindControl("gvWaterLevels"), GridView)
            Dim strSiteId As String = DirectCast(e.Item.DataItem, System.Data.DataRowView)("strSiteId").ToString()
            Dim TimePeriod As String = ""
            Dim rbPeriod As New RadioButton()
            If rbPeriod.Checked Then
                TimePeriod = "0"
            ElseIf rbfive.Checked Then
                TimePeriod = "5"
            End If
            'check other RadioButton
            gv.DataSource = GetWaterLevels(strSiteId, TimePeriod)
            'input values to function
            gv.DataBind()
        End If
    End Sub

    Just my example, change your own id and variables.

    Thanks,

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Pass radio button Value into DataSource Method of Repeater

    07-07-2009, 8:40 AM
    • Member
      point Member
    • kramer9802
    • Member since 06-30-2009, 11:50 AM
    • Posts 2

    That worked great! Thanks.

Page 1 of 1 (3 items)