EDN Admin
Well-known member
Hello,<br/>
<br/>
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)<br/>
<br/>
so depending of the administrator logged on, the sqldatasource should load the right data.<br/>
<br/>
actually i have 3 kinds od admin: <br/>
<br/>
1-superadmin: when he is logged on, the grid dispaly all cities hotel admin and their branches admin (actually this work finally)<br/>
<br/>
2-city hotel admin : when he is logged on, the grid display the right results .<br/>
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)<br/>
<br/>
<br/>
3-branch hotel admin: same problem of city hotel admin:<br/>
<br/>
thank you for your help.<br/>
<br/>
***asp.net***<br/>
1-the grid:
<pre class="prettyprint <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>
[/code]
2-Sql data source
<pre class="prettyprint <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>
[/code]
****code behind ****
<pre class="prettyprint 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");
}
}
[/code]
<br/>
View the full article
<br/>
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)<br/>
<br/>
so depending of the administrator logged on, the sqldatasource should load the right data.<br/>
<br/>
actually i have 3 kinds od admin: <br/>
<br/>
1-superadmin: when he is logged on, the grid dispaly all cities hotel admin and their branches admin (actually this work finally)<br/>
<br/>
2-city hotel admin : when he is logged on, the grid display the right results .<br/>
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)<br/>
<br/>
<br/>
3-branch hotel admin: same problem of city hotel admin:<br/>
<br/>
thank you for your help.<br/>
<br/>
***asp.net***<br/>
1-the grid:
<pre class="prettyprint <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>
[/code]
2-Sql data source
<pre class="prettyprint <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>
[/code]
****code behind ****
<pre class="prettyprint 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");
}
}
[/code]
<br/>
View the full article