Click here to Skip to main content
16,003,404 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i have a telerik radGrid that 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 grid show the result.

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 also the right results but the grid commands like (edit and delete and add a new record) are freezed and cannot display the right form (addWebAdminCityBranchForm.ascx) .

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

Thank you in advance.



the first form that contain the grid is:

****asp.net****


ASP.NET
<td valign="top">
    <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>
        </td>

<td>
 <asp:SqlDataSource ID="viewAdminCityBranchWebDetails" runat="server" 
        ConnectionString="<%$ ConnectionStrings:SmartBookingEngineConn %>" 
        > </asp:SqlDataSource>

      <telerik:RadTextBox ID="txtcityID"  runat="server" Height="28px" Visible="false" Width="197px">
      </telerik:RadTextBox>
      
      <telerik:RadTextBox ID="txtbranchID"  runat="server" Height="28px" Visible="false" Width="197px">
      </telerik:RadTextBox>

       <telerik:RadTextBox ID="txtuser"  runat="server" Height="28px" Visible="false" Width="197px">
      </telerik:RadTextBox>
<telerik:RadAjaxManagerProxy ID="rp"  runat="server">
</telerik:RadAjaxManagerProxy>
</td>


*****c# code ******

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 (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");
           }

       }

protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
       {
           // Insert Command
           .............

       }

protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
       {
          // Update Command
           .............

       }

protected void gvS_ItemCommand(object source, GridCommandEventArgs e)
       {
           if (e.CommandName.ToString() == "find")
           {
               if (e.Item is GridDataItem)
               {
                   GridDataItem item = (GridDataItem)e.Item;
                   string strTxt = item["loginID"].Text.ToString();
                   string mysql = "DELETE from tblAdminCityBranchWebLogin where loginID='" + strTxt + "'";
                   db.sqlServer.executeQuery(mysql);
                   gvS.Rebind();
               }
           }
       }



when i click on ad new record or edit command of the grid view the form: addWebAdminCityBranchForm.ascx is displayed; below is the code:

****asp.net****
ASP.NET
<table>
    <tr>
      <td width="35%">
            <asp:Label ID="lblMessage" runat="server" ForeColor="Red"></asp:Label>
            <asp:Label ID="lblUserType" runat="server" ForeColor="Red" Visible="False"></asp:Label>
       </td>
    </tr>
    <tr>
        <td width="25%">
            <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
        </td>
        <td width="75%">
            <telerik:RadTextBox ID="txtName"  runat="server" 
                Text='<%# DataBinder.Eval( Container, "DataItem.Name"  ) %>' 
                Width="250px">
            </telerik:RadTextBox>
            </td>
    </tr>
    <tr>
        <td width="15%">
            <asp:Label ID="Label25" runat="server" Text="User Name"></asp:Label>
        </td>
        <td width="35%">
            <telerik:RadTextBox ID="txtUserName"  runat="server" 
                Text='<%# DataBinder.Eval( Container, "DataItem.userName"  ) %>' 
                Width="250px">
            </telerik:RadTextBox>
        </td>
    </tr>
    <tr>
        <td width="15%" valign="top">
            <asp:Label ID="Label23" runat="server" Text="Password"></asp:Label>
        </td>
        <td width="35%">
            <telerik:RadTextBox ID="txtPassword"  runat="server" 
                Text='<%# DataBinder.Eval( Container, "DataItem.password"  ) %>' 
                Width="250px">
            </telerik:RadTextBox>
        </td>
    </tr>
    <tr>
        <td width="15%" valign="top">
            <asp:Label ID="Label2" runat="server" Text="City"></asp:Label>
        </td>
        <td width="35%">
          
           <asp:DropDownList ID="ddlCity" runat="server" DataSourceID="tblCity" 
                DataTextField="city" DataValueField="cityID" 
                SelectedValue='<%# Bind("cityID") %>' AutoPostBack="true" 
                AppendDataBoundItems="true" 
                onselectedindexchanged="ddlCity_SelectedIndexChanged">
            <asp:ListItem Text="--Select--" Value=""></asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="tblCity" runat="server" 
                ConnectionString="<%$ ConnectionStrings:SmartBookingEngineConn %>" 
                SelectCommand="SELECT [cityID],[city] FROM [viewCityAdmin]">
            </asp:SqlDataSource>
        </td>
    </tr>
    <tr>
        <td width="15%" valign="top">
            <asp:Label ID="Label3" runat="server" Text="Branch"></asp:Label>
        </td>
        <td width="35%">
          
            <asp:DropDownList ID="ddlBranch" runat="server" DataSourceID="tblBranch" 
                DataTextField="Branch" DataValueField="BranchID">
            <asp:ListItem Text="----" Value=""></asp:ListItem>
            </asp:DropDownList>

            <asp:SqlDataSource ID="tblBranch" runat="server" ConnectionString="<%$ ConnectionStrings:SmartBookingEngineConn %>" SelectCommand="SELECT [BranchID],[Branch] FROM [tblBranch] WHERE ([CityID]=@cityID)">
               <SelectParameters>
                <asp:ControlParameter Name="cityID" ControlID="ddlCity" PropertyName="SelectedValue" Type="String" />
               </SelectParameters>
            </asp:SqlDataSource>
      
          
        </td>
    </tr>
    <tr>
        <td width="15%">
            <asp:Label ID="Label26" runat="server" Text="User Type"></asp:Label>
         </td>
        <td width="35%">
       
            <asp:DropDownList ID="ddlUserType" runat="server" DataSourceID="tblUserType" 
                DataTextField="userType" DataValueField="userTypeID" SelectedValue='<%# Bind("userTypeID") %>' AppendDataBoundItems="True">                           
                 <asp:ListItem Text="--Select--" Value=""></asp:ListItem> 
            </asp:DropDownList>
            <asp:SqlDataSource ID="tblUserType" runat="server" 
                ConnectionString="<%$ ConnectionStrings:SmartBookingEngineConn %>" 
                SelectCommand="SELECT [userTypeID], [userType] FROM [tblUserTypeMaster]">
            </asp:SqlDataSource>
        </td>
    </tr>
    <tr>
        <td width="15%">
             </td>
        <td width="35%">
            <telerik:RadTextBox ID="rid"  runat="server" Height="28px" 
                Text='<%# DataBinder.Eval( Container, "DataItem.loginID"  ) %>' 
                Visible="False" Width="197px">
            </telerik:RadTextBox>
        </td>
    </tr>
    <tr>
        <td width="15%">
             </td>
        <td align="center" width="50%">
            <asp:Button ID="btnUpdate" runat="server" CommandName="Update" 
                onclick="btnUpdate_Click" text="Update" 
                Visible="<%# !(DataItem is Telerik.Web.UI.GridInsertionObject) %>" />
            <asp:Button ID="btnInsert" runat="server" CommandName="PerformInsert" 
                text="Save" Visible="<%# DataItem is Telerik.Web.UI.GridInsertionObject %>" />
            <asp:Button ID="btnCancel" runat="server" causesvalidation="False" 
                commandname="Cancel" text="Cancel" />
        </td>
    </tr>
</table>
Posted

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