Good day all
i have a UserControl Defined like this
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="resourceSelectorNew.ascx.cs" Inherits="resourceSelectorNew" %>
<table border=0><tr>
<td style="font-weight: bold; font-size: 10pt; font-family: Verdana">
Select resource...<br />
<asp:Panel ID="Panel1" runat="server" ScrollBars="Auto" Width="800px"
Wrap="False" BackColor="Orange" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px">
<asp:DropDownList ID="drplstResourceTypes" runat="server" AutoPostBack="True" DataSourceID="SqlDataSourceResourceTypes"
DataTextField="Descr" DataValueField="ID" OnSelectedIndexChanged="drplstResourceTypes_SelectedIndexChanged" Font-Bold="True" Font-Names="Verdana" Font-Overline="False" Font-Size="10pt">
</asp:DropDownList>
</asp:Panel>
<asp:SqlDataSource ID="SqlDataSourceResourceTypes" runat="server" SelectCommand="SELECT '' [ID], '' [Descr]
UNION
SELECT DISTINCT t.ID [ID], t.DESCR [Descr]
FROM TBL_RTYPE t">
</asp:SqlDataSource>
</td>
</tr></table>
and this Usercontrol is hosted in my other ASpx page and i have a gridview in that page defined like this
Code:
<asp:GridView ID="grdViewTreeRules" runat="server" AutoGenerateColumns="False"
BackColor="Moccasin" BorderColor="DarkOrange" BorderStyle="Solid" BorderWidth="2px"
CellPadding="0" Font-Names="Verdana"
Font-Size="9pt" ForeColor="Black" PageSize="2" Style="border-right: darkorange 2px solid;
border-top: darkorange 2px solid; border-left: darkorange 2px solid; border-bottom: darkorange 2px solid"
Width="100%" OnSelectedIndexChanged="grdViewTreeRules_SelectedIndexChanged" OnRowDataBound="grdViewTreeRules_RowDataBound">
<RowStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle BackColor="DarkOrange" Font-Names="Verdana" Font-Size="10pt" />
<AlternatingRowStyle BackColor="PapayaWhip" BorderWidth="0px" />
<Columns>
<asp:TemplateField HeaderText="Select" SortExpression="ID">
<ItemTemplate>
<asp:CheckBox ID="chkbx" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" SortExpression="Descr">
<ItemTemplate>
<asp:Label ID=lblDescription Text='<%# Bind("Descr") %>' runat ="server" >
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Parent" SortExpression="Parent">
<ItemTemplate>
<asp:Label ID="lblParent" Visible ="false" Text='<%# Bind("Parent")%>' runat="server"></asp:Label>
<asp:Label ID="lblDescr" Visible ="false" Text='<%# Bind("Parent_Descr")%>' runat="server"></asp:Label>
<asp:DropDownList ID="drplstparent" runat="server" BackColor="Transparent">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
on the aspx page on the server side, i want to bind the Gridview everytime a selection is made on the usercontrol so i have wrote to code to bind the grid everytime postback is fired and the usercontrol loads like this
Code:
protected void resourceSelectorNew1_Load(object sender, EventArgs e)
{
BLL.BLL obj = new BLL.BLL();
DataSet ds = new DataSet();
String DB = Convert.ToString(Session["ActiveDatabase"]);
String SelectedResourceID = Convert.ToString(Session["ResourceTypeID"]);
try
{
ds = obj.Get_Resource_Based_Type_ID(SelectedResourceID, DB);
grdViewTreeRules.DataSource = ds;
grdViewTreeRules.DataBind();
}
catch (SqlException ex)
{
lblStatus.Text = ex.Message;
}
finally
{
obj = null;
}
}
and i have a drop-down in my grid so am binding it in the RowDataBound event like this
Code:
protected void grdViewTreeRules_RowDataBound(object sender, GridViewRowEventArgs e)
{
BLL.BLL obj = new BLL.BLL();
try
{
DataSet ds = new DataSet();
// String ResourceTypeID = Convert.ToString(Session["ResourceTypeID"]);
//String ResourceTypeID = Convert.ToString(Session["SelectedResourceID"]);
String DB = Convert.ToString(Session["ActiveDatabase"]);
if (e.Row.RowType == DataControlRowType.DataRow) //skip header row
{
DropDownList ddl = (DropDownList)e.Row.Cells[2].FindControl("drplstparent");
Label label = (Label)e.Row.Cells[2].FindControl("lblParent");
Label label2 = (Label)e.Row.Cells[2].FindControl("lblDescr");
if (label2.Text != "") //When there is data in the Grid
{
ds = obj.Get_Resource_by_ID(label.Text, DB);
//ddl.SelectedValue = label2.Text;
//ddl.SelectedValue = label.Text.ToString();
String Test_Value = ((DataRowView)e.Row.DataItem)["Parent"].ToString();
SelectValueFrmDDL(ddl,Test_Value);
ddl.SelectedValue = Test_Value;
ddl.DataSource = ds;
ddl.DataTextField = "Descr";
ddl.DataValueField = "ID";
ddl.DataBind();
}
else //When there is no data in the Grid
{
ds = obj.Get_Resource_by_ID(label.Text, DB);
//ddl.SelectedValue = label2.Text;
ddl.DataSource = ds;
ddl.DataTextField = "Descr";
ddl.DataValueField = "ID";
ddl.DataBind();
}
}
}
catch (SqlException ex)
{
lblStatus.Text = ex.Message;
}
}
now my problem is that every time the selection is made or every time resourceSelectorNew1_Load event is Fired, the Grid is not Updated until i press F5
Thank you