Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
on my webform, I have one grid, 2 dropdownlist and one datepicker control.
When I select items from my both dropdown and date from datepicker control, I want to populate my grid based on above mention control selections.
But, my problem is on selection, my grid is not showing any data.
Please help.
Code I am using is below: ASPX.CODE
XML
<asp:DropDownList                            ID="ddlmenutype" OnSelectedIndexChanged ="ddlmenutype_SelectedIndexChanged" runat="server"                            Height="20px" Width="90px" AutoPostBack="True" ToolTip="Select Menu Type" ForeColor="Black"                            Font-Size="12px">                        <asp:ListItem Value="B">BreakFast</asp:ListItem>                        <asp:ListItem Value="L">Lunch</asp:ListItem>                        <asp:ListItem Value="A">AlaCarte</asp:ListItem>                        <asp:ListItem Value="M">BreakFast-F</asp:ListItem>                        <asp:ListItem Value="N">Lunch-F</asp:ListItem>                    </asp:DropDownList>
<%@ Page Title="" Language="vb" AutoEventWireup="True" MasterPageFile="~/Dss.Master" CodeBehind="ProductionRecordmain.aspx.vb" Inherits="DSS.ProductionRecordmain" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<asp:DropDownList
                            ID="ddlmenutype" OnSelectedIndexChanged ="ddlmenutype_SelectedIndexChanged" runat="server"
                            Height="20px" Width="90px" AutoPostBack="True" ToolTip="Select Menu Type" ForeColor="Black"
                            Font-Size="12px">
                        <asp:ListItem Value="B">Br</asp:ListItem>
                        <asp:ListItem Value="L">Lu</asp:ListItem>
                        <asp:ListItem Value="A">Al</asp:ListItem>
                        <asp:ListItem Value="M">BrF</asp:ListItem>
                        <asp:ListItem Value="N">LuF</asp:ListItem>
                    </asp:DropDownList>
<asp:DropDownList
                        ID="ddlSch" runat="server" Height="20px" Width="203px" AutoPostBack="True" Font-Size="12px"
                        >
                    </asp:DropDownList>
<telerik:RadDatePicker
                        ID="RadDatePick" Runat="server" AutoPostBack="True" Culture="en-US"
                        Skin="Outlook" Width="100px" Font-Size="10px" ForeColor="Black">
<Calendar runat="server" UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x"
                            Skin="Outlook"></Calendar>

<DateInput  runat ="server" DisplayDateFormat="M/d/yyyy" DateFormat="M/d/yyyy" AutoPostBack="True"></DateInput>

<DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>
                    </telerik:RadDatePicker>

<telerik:RadGrid ID="GD_Prod" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            GridLines="None" Height="261px" ShowHeader="False" Skin="Outlook" Width="1107px"
             AllowAutomaticInserts="True" AllowAutomaticUpdates="True">
            <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
                <Selecting AllowRowSelect="True" />
                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
            </ClientSettings>
            <MasterTableView CommandItemDisplay="Bottom"
    EditMode="PopUp" InsertItemPageIndexAction="ShowItemOnCurrentPage">
<CommandItemSettings
        AddNewRecordText="Add New item" ShowRefreshButton="False"></CommandItemSettings>
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
    <Columns>
 <telerik:GridBoundColumn DataField="port_recipe_num"
            HeaderText="port_recipe_num" SortExpression="port_recipe_num"
            UniqueName="port_recipe_num">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="DESC_ALT" HeaderText="DESC_ALT"
            SortExpression="DESC_ALT" UniqueName="DESC_ALT">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="port_no_servings"
            HeaderText="port_no_servings" SortExpression="port_no_servings"
            UniqueName="port_no_servings">
        </telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="STD_NUM_OF_SERVING" DataType="System.Int32"
            HeaderText="STD_NUM_OF_SERVING" SortExpression="STD_NUM_OF_SERVING"
            UniqueName="STD_NUM_OF_SERVING">
        </telerik:GridBoundColumn>
     </Columns>
</MasterTableView>
        </telerik:RadGrid>


VB CODE:
VB
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Data.SqlClient
Imports Telerik.Web.UI
Public Class ProductionRecordmain
    Inherits System.Web.UI.Page
Public Sub BindGrid()
        Dim con1 As New SqlConnection(ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString)
        Dim cmd1 As New SqlCommand
        Dim ada1 As New SqlDataAdapter("FN_PR_GetRec", con1)
        Dim ds1 As New DataSet
        con1.Open()
        ada1.SelectCommand.CommandType = CommandType.StoredProcedure
        cmd1.Parameters.Add("@RadDatePick", SqlDbType.DateTime).Direction = ParameterDirection.Input
        cmd1.Parameters("@RadDatePick").Value = RadDatePick.SelectedDate
        cmd1.Parameters.Add("@ddlSch", SqlDbType.Char).Direction = ParameterDirection.Input
        cmd1.Parameters("@ddlSch").Value = ddlSch.SelectedValue
        cmd1.Parameters.Add("@ddlMenuType", SqlDbType.Char).Direction = ParameterDirection.Input
        cmd1.Parameters("@ddlMenuType").Value = ddlmenutype.SelectedValue
        ada1.Fill(ds1, "FN_PR_GetRec")
        con1.Close()
        Dim dv As DataView = ds1.Tables(0).DefaultView
        GD_Prod.DataSource = dv

 Private Sub ddlSch_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSch.Load
        Dim Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString)
        Dim cmd As New SqlCommand
        Dim ada As New SqlDataAdapter("FN_PR_SchName", Conn)
        Dim ds As New DataSet
        ada.SelectCommand.CommandType = CommandType.StoredProcedure
        ada.Fill(ds, "FN_PR_SchName")
        ddlSch.DataSource = ds
        ddlSch.DataTextField = "LOCATION_NAME"
        ddlSch.DataBind()
    End Sub
Private Sub ddlmenutype_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlmenutype.SelectedIndexChanged
        If Not IsPostBack Then
            BindGrid()
            GD_Prod.DataBind()
        End If
    End Sub
Private Sub ddlSch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSch.SelectedIndexChanged
        If Not IsPostBack Then
            BindGrid()
            GD_Prod.DataBind()
        End If
    End Sub

    Private Sub RadDatePick_SelectedDateChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs) Handles RadDatePick.SelectedDateChanged
        If Not IsPostBack Then
            BindGrid()
            GD_Prod.DataBind()
        End If
    End Sub

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            BindGrid()
            GD_Prod.DataBind()
        End If
    End Sub

    Private Sub GD_Prod_PageIndexChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridPageChangedEventArgs) Handles GD_Prod.PageIndexChanged
        GD_Prod.CurrentPageIndex = e.NewPageIndex
        BindGrid()
        GD_Prod.DataBind()
    End Sub
End Class
Posted
Updated 28-Dec-10 8:58am
v2
Comments
JF2015 28-Dec-10 14:58pm    
Edited to fix code formatting.
[no name] 28-Dec-10 15:20pm    
VB is ugly no matter how it is formatted :)
[no name] 28-Dec-10 15:21pm    
And have you debugged this?
Rohit.Net100 28-Dec-10 15:28pm    
yes i debug it. can you plz help me what i am missing in code.

1 solution

On selectedindexchange event the Ispostback will always be true.
" If Not IsPostBack Then
BindData()......."

it will never reach binddata() line. Remove the condition and check once.
 
Share this answer
 
Comments
Rohit.Net100 28-Dec-10 15:48pm    
I removed the condition, but still no change.
maheswariragu 29-Dec-10 14:23pm    
Doesnt it trigger the selectedIndexChange event?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900