Click here to Skip to main content
15,894,955 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

i have a telerik radGrid that have sqldatasource which enable it to display the list of all hotel branches admins by hotel city.(a hotel city has different branches of hotels)

so depending of the administrator logged on, the sqldatasource should load the right data.

actually i have 3 kinds od admin:

1-superadmin: when he is logged on, the grid dispaly all cities hotel admin and their branches admin (actually this work finally)

2-city hotel admin : when he is logged on, the grid display the right results .
the problem is that when i click on the edit command of the grid, sqldatasource load the wrong data (it show the result of sqldatasource which is by default and not which is in the right case)


3-branch hotel admin: same problem of city hotel admin:

thank you for your help.

***asp.net***
1-the grid:
ASP.NET
    <telerik:RadGrid ID="gvS"  runat="server" DataSourceID="viewAdminCityBranchWebDetails" 
     GridLines="None" AllowPaging="True" AllowSorting="True" 
            Width="99%" AutoGenerateColumns="False"
            ShowStatusBar="True" OnPreRender="RadGrid1_PreRender" 
            OnNeedDataSource="RadGrid1_NeedDataSource" 
            OnUpdateCommand="RadGrid1_UpdateCommand" 
            OnInsertCommand="RadGrid1_InsertCommand" 
            OnDeleteCommand="RadGrid1_DeleteCommand" Skin="Black" 
        ShowGroupPanel="True"  önitemcommand="gvS_ItemCommand">
            
        
<HeaderContextMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</HeaderContextMenu>

        <AlternatingItemStyle BackColor="#CCCCCC" ForeColor="Black" />

        <ItemStyle ForeColor="White" />

<MasterTableView autogeneratecolumns="False" datasourceid="viewAdminCityBranchWebDetails"
EditMode="PopUp" commanditemdisplay="Top" >
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>

<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<GroupByExpressions>
                    <telerik:GridGroupByExpression>
                        <SelectFields>
                            <telerik:GridGroupByField FieldAlias="City" FieldName="City" HeaderText="Hotel City"></telerik:GridGroupByField>
                        </SelectFields>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldName="City"></telerik:GridGroupByField>
                        </GroupByFields>
                    </telerik:GridGroupByExpression>

                    <telerik:GridGroupByExpression>
                        <SelectFields>
                            <telerik:GridGroupByField FieldAlias="Branch" FieldName="Branch" HeaderText="Hotel Branchs"></telerik:GridGroupByField>
                        </SelectFields>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldName="Branch"></telerik:GridGroupByField>
                        </GroupByFields>
                    </telerik:GridGroupByExpression>
</GroupByExpressions>

    <Columns>
        <telerik:GridBoundColumn DataField="Name" HeaderText="Name" 
            SortExpression="Name" UniqueName="Name">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="loginID" DataType="System.Decimal" 
            HeaderText="loginID" ReadOnly="True" SortExpression="loginID" 
            UniqueName="loginID" Visible="false">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="userName" HeaderText="User Name" 
            SortExpression="userName" UniqueName="userName">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="password" HeaderText="Password" 
            SortExpression="password" UniqueName="password">
        </telerik:GridBoundColumn>
         <telerik:GridBoundColumn DataField="userTypeID" HeaderText="userType ID" 
            SortExpression="userTypeID" UniqueName="userTypeID" Visible="false">
        </telerik:GridBoundColumn>
         <telerik:GridBoundColumn DataField="userType" HeaderText="User Type" 
            SortExpression="userType" UniqueName="userType">
        </telerik:GridBoundColumn>

         <telerik:GridBoundColumn DataField="cityID" HeaderText="City ID" 
            SortExpression="cityID" UniqueName="cityID" Visible="false">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="city" HeaderText="City" 
            SortExpression="city" UniqueName="city">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="branchID" HeaderText="Branch ID" 
            SortExpression="branchID" UniqueName="branchID" Visible="false">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="branch" HeaderText="Branch" 
            SortExpression="branch" UniqueName="branch">
        </telerik:GridBoundColumn>

        <telerik:GridBoundColumn DataField="createdDate" DataType="System.DateTime" 
            HeaderText="Created Date" SortExpression="createdDate" UniqueName="createdDate">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="updatedDate" DataType="System.DateTime" 
            HeaderText="Updated Date" SortExpression="updatedDate" UniqueName="updatedDate" DataFormatString="{0:MM/dd/yyyy}" >
        </telerik:GridBoundColumn>
          <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
                    <ItemStyle Font-Italic="True" Font-Underline="True" ForeColor="#CC3300" />
                    </telerik:GridEditCommandColumn>
                    <telerik:GridButtonColumn CommandName="find" HeaderText="" 
            Text="Delete" UniqueName="column">
                        <ItemStyle Font-Italic="True" Font-Underline="True" ForeColor="#CC3300" />
        </telerik:GridButtonColumn>   
    </Columns>
     <EditFormSettings UserControlName="addWebAdminCityBranchForm.ascx" EditFormType="WebUserControl" CaptionFormatString=" Manage Admin Form" FormStyle-Font-Bold=true >

<FormStyle Font-Bold="True"></FormStyle>

     <PopUpSettings Width="70%" />
                    <EditColumn UniqueName="EditCommandColumn1">
                    </EditColumn>
                </EditFormSettings>
    
</MasterTableView>


                
        <ClientSettings AllowDragToGroup="True">
        </ClientSettings>


                
<FilterMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</FilterMenu>
    </telerik:RadGrid>

2-Sql data source
ASP.NET
<asp:SqlDataSource ID="viewAdminCityBranchWebDetails" runat="server" 
        ConnectionString="<%$ ConnectionStrings:SmartBookingEngineConn %>" 
        SelectCommand="SELECT [loginID], [Name], [userName], [password],[CityID],[city],[branchID],[Branch],[userTypeID], [userType], [createdDate],[updatedDate] FROM [ViewCityBranchWebAdmin]"
        > </asp:SqlDataSource>

*** C# ***
C#
public string UserName;
        public string UserType;
        protected void Page_Load(object sender, EventArgs e)
        {
            rp.AjaxSettings.AddAjaxSetting(gvS, gvS);
            UserName = Session["uname"].ToString();
            UserType = Session["userType"].ToString();
            if (Session["uname"] != null)
            {
                txtuser.Text = UserType;
                if (!IsPostBack)
                {
                    if (UserType == "SuperAdmin")
                    {
                        viewAdminCityBranchWebDetails.SelectCommand = "SELECT loginID,Name,userName,password,CityID,city,branchID,Branch,userTypeID,userType,createdDate, updatedDate FROM ViewCityBranchWebAdmin";
                        viewAdminCityBranchWebDetails.DataBind();

                    }
                    else if (UserType == "CityAdmin")
                    {
                        txtcityID.Text = Session["cityID"].ToString();

                        viewAdminCityBranchWebDetails.SelectCommand = "SELECT loginID,Name,userName,password,CityID,city,branchID,Branch,userTypeID,userType,createdDate, updatedDate FROM ViewCityBranchWebAdmin Where CityID=@cityID";
                        viewAdminCityBranchWebDetails.SelectParameters.Add("cityID", txtcityID.Text.ToString());
                        viewAdminCityBranchWebDetails.DataBind();
                    }
                    //branches Admin

                    else if (UserType == "Super Admin")
                    {
                        txtcityID.Text = Session["cityID"].ToString();
                        txtbranchID.Text = Session["branchID"].ToString();

                        viewAdminCityBranchWebDetails.SelectCommand = "SELECT loginID,Name,userName,password,CityID,city,branchID,Branch,userTypeID,userType,createdDate, updatedDate FROM ViewCityBranchWebAdmin Where CityID=@cityID and branchID=@branchID";
                        viewAdminCityBranchWebDetails.SelectParameters.Add("cityID", txtcityID.Text.ToString());
                        viewAdminCityBranchWebDetails.SelectParameters.Add("branchID", txtbranchID.Text.ToString());
                        viewAdminCityBranchWebDetails.DataBind();
                    }

                }
            }
                
            else
            {
                Response.Redirect("frmlogin1.aspx");
            }
                
        }
Posted
Updated 28-Nov-12 18:40pm
v4
Comments
pradiprenushe 29-Nov-12 0:48am    
Remove ispostback check. You will understand what is happening.

1 solution

Actuallay the problem was in the select command itself, so this is the solution:

***C# code behind page load****

C#
protected void Page_Load(object sender, EventArgs e)
      {
          rp.AjaxSettings.AddAjaxSetting(gvS, gvS);
          UserName = Session["uname"].ToString();
          UserType = Session["userType"].ToString();
          if (Session["uname"] != null)
          {
              string sql;
              txtuser.Text = UserType;
          
             if (UserType == "SuperAdmin")
                  {
                      sql = "SELECT loginID,Name,userName,password,CityID,city,branchID,Branch,userTypeID,userType,createdDate, updatedDate FROM ViewCityBranchWebAdmin ";
                      viewAdminCityBranchWebDetails.SelectCommand = sql;
                      gvS.DataBind();

                  }
                  else if (UserType == "CityAdmin")
                  {
                      txtcityID.Text = Session["cityID"].ToString();

                      sql = "SELECT loginID,Name,userName,password,CityID,city,branchID,Branch,userTypeID,userType,createdDate, updatedDate FROM ViewCityBranchWebAdmin Where CityID='" + txtcityID.Text.ToString() + "'";
                      viewAdminCityBranchWebDetails.SelectCommand = sql;
                      gvS.DataBind();

                  }
                  //branches Admin

                  else if (UserType == "Super Admin")
                  {
                      txtcityID.Text = Session["cityID"].ToString();
                      txtbranchID.Text = Session["branchID"].ToString();

                      sql = "SELECT loginID,Name,userName,password,CityID,city,branchID,Branch,userTypeID,userType,createdDate, updatedDate FROM ViewCityBranchWebAdmin Where CityID='" + txtcityID.Text.ToString() + "'and branchID='" + txtbranchID.Text.ToString() + "'";
                      viewAdminCityBranchWebDetails.SelectCommand = sql;
                      gvS.DataBind();
                  }

              }
        
      }
 
Share this answer
 

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