Jan 08, 2012, 5:43 PM
create direct event in runtime to MenuItem
Dear All,
I Need your Help
how can i add direct event to MenuItem in Runtime , this is my code :
asp.net Designer
Now I need to create direct event in runtime to execute code in Method (SetPeriodSession)
i used the previous code , but it's not working ???
thanks in advance
I Need your Help
how can i add direct event to MenuItem in Runtime , this is my code :
asp.net Designer
<ext:MenuItem ID="MenuItem1" runat="server" Width="300" Text="Select Period" Icon="BookOpen">
<Menu>
<ext:Menu ID="Menu2" runat="server" BoxMinWidth="300">
<Items/>
<DirectEvents>
<ItemClick OnEvent="SetPeriodSession" />
</DirectEvents>
</ext:Menu>
</Menu>
</ext:MenuItem>
Code:public void FillPeriods()
{
SqlConnection con = Connections.GetSQLConnection();
string command="SELECT dbo.Schedules.EffectiveDate, dbo.Schedules.ScheduleCode, dbo.Schedules.GroupID,"
+"dbo.Schedules.PeriodID FROM dbo.Schedules INNER JOIN dbo.Teachers ON dbo.Schedules.TeacherID ="
+"dbo.Teachers.TID WHERE (dbo.Schedules.TeacherID = @TID)ORDER BY dbo.Schedules.PeriodID";
SqlCommand com=new SqlCommand(command,con);
com.Parameters.AddWithValue("@TID", Session["TeacherID"].ToString());
con.Open();
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
Ext.Net.MenuItem.Config config = new Ext.Net.MenuItem.Config();
config.Icon = Icon.BookEdit;
config.Text = reader[3].ToString();
config.DirectEvents.Click.ExtraParams.Add(new Ext.Net.Parameter("selected", reader[3].ToString()));
config.DirectEvents.Click.Event += SetPeriodSession;
Menu2.Items.Add(new Ext.Net.MenuItem(config));
}
Menu2.DataBind();
reader.Close();
con.Close();
}
public void SetPeriodSession(object o , DirectEventArgs e)
{
if (e.Success)
{
Session["PeriodNO"] = e.ExtraParams[0].Value;
SqlConnection con = Connections.GetSQLConnection();
SqlCommand com = new SqlCommand("select GroupID from Schedules where PeriodID=@PID and TeacherID=@TID and status='Active'", con);
com.Parameters.AddWithValue("@PID", Session["PeriodNO"].ToString());
com.Parameters.AddWithValue("@TID", Session["TeacherID"].ToString());
con.Open();
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
Session["GroupNO"] = GroupsOperations.GetGroupNo(int.Parse(dr[0].ToString()));
lblGroupNo.Text = Session["GroupNO"].ToString();
}
dr.Close();
con.Close();
}
}
----------------------------------------------------------------------------------------------------------------------------------Now I need to create direct event in runtime to execute code in Method (SetPeriodSession)
i used the previous code , but it's not working ???
thanks in advance
Last edited by geoffrey.mcgill; Jan 08, 2012 at 6:04 PM.
Reason: please use [CODE] tags