|
|
Hai,
It is working perfectly in 2.0 where did u paste the code?
after the login page ,u will get a page ,in that page ,inside the pageload event just paste this code
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
|
|
|
|
|
The error came like these when click on the back button.
"Use the new keyword to create an object instance.
Check to determine if the objects is null before calling the method."
|
|
|
|
|
try this eg:
username and password is admin
Default.aspx
]]>
<title>Untitled Page
<asp:textbox id="TextBox1" runat="server" style="z-index: 100; left: 453px; position: absolute;<br mode=" hold=" /> top: 93px" xmlns:asp="#unknown">
<asp:textbox id="TextBox2" runat="server" style="z-index: 101; left: 462px; position: absolute;<br mode=" hold=" /> top: 158px" textmode="Password" xmlns:asp="#unknown">
<asp:button id="Button1" runat="server" onclick="Button1_Click" style="z-index: 102;<br mode=" hold=" /> left: 514px; position: absolute; top: 250px" text="Button" xmlns:asp="#unknown">
<asp:label id="Label1" runat="server" style="z-index: 104; left: 323px; position: absolute;<br mode=" hold=" /> top: 97px" text="Enter the username" xmlns:asp="#unknown">
<asp:label id="Label2" runat="server" style="z-index: 104; left: 327px; position: absolute;<br mode=" hold=" /> top: 158px" text=" Enter the password" xmlns:asp="#unknown">
Default2.aspx
]]>
<title>Untitled Page
<asp:label id="Label1" runat="server" font-bold="True" font-size="XX-Large" forecolor="Red" xmlns:asp="#unknown">
Height="86px" Style="z-index: 100; left: 239px; position: absolute; top: 26px"
Text="Welcome" Width="295px">
<asp:linkbutton id="LinkButton1" runat="server" onclick="LinkButton1_Click" style="z-index: 102;<br mode=" hold=" /> left: 637px; position: absolute; top: 26px" xmlns:asp="#unknown">Logout
Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Focus();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "admin" && TextBox2.Text == "admin")
{
Server.Transfer("Default2.aspx");
}
else
{
Response.Write("Wrong username or password");
}
}
}
Default2.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Session.Abandon();
Server.Transfer("Default.aspx");
}
}
|
|
|
|
|
|
Is it possible to create a Frameset in Visual studio 2005? How?
|
|
|
|
|
Because frames are not fully supported by the w3c, it is not implemented in Asp.net 2.0. You can implement it only throw editing in the source view.
you can also create the HtmlGenericControl object that will eventually render as an iframe and specify whatever attributes this iframe will have:
// Create new iframe control
HtmlGenericControl searchFrame = new HtmlGenericControl("iframe");
searchFrame.ID = "searchFrame";
searchFrame.Attributes.Add("class", "searchFrame");
searchFrame.Attributes.Add("frameborder", "0");
Then, I can add it to the PlaceHolder’s controls collection:
// Add it to the Controls collection of the PlaceHolder control
searchHolder.Controls.Add(searchFrame);
Finally, I add the PlaceHolder control into my ascx document where I’d like the iframe to eventually be:
<div class="searchContainer">
<asp:PlaceHolder id="searchHolder" runat="server" />
</div>
Now, an iframe will appear in the outputted HTML code where the placeholder once was.
The similar type of things can be implemented ASP.NET2.0 by "Master Page"
The miracle is this--the more we share, the more we have.
|
|
|
|
|
which method is more appropriate for use with XML?
-> xmlDocument
-> xPathDocumrnt
-> Datatset
|
|
|
|
|
Depends on what you want to achieve. For navigation within an XML the best choice will be xpath I think. XmlDocument could be also nice but you only have this navigation like direct child/parents etc. DataSet is better when trying to use XML like a database.
By the way, this is not your homework, is it?
Regards
Sebastian
P.S.: Heard that XPath will is slow... maybe this will affect your choice.
|
|
|
|
|
I have developed a chat application.
i am displaying chat messages using gridview in a div.I am using gridview in update panel(ajax).With every timer_tick I update the gridview.My timer control s in control template of update panel.The problem is I have to maintain the scroll position after after timer tick event ie after the grid gets the data.
I ahve altried all the options on the net.None of them is working.Help me Its urgent.
This problem is buggin me alot.
Here is the code .aspx
]]>
<title>Welcome to chat application
<%----%>
<asp:scriptmanager id="ScriptManager1" runat="server" xmlns:asp="#unknown">
<asp:updatepanel id="UpdatePanel1" runat="server" xmlns:asp="#unknown">
<contenttemplate>
<asp:gridview showheader="false" width="1%" cellpadding="0" cellspacing="0" id="gvmsg" gridlines="None" runat="Server" autogeneratecolumns="false">
<columns> <asp:templatefield>
<itemtemplate>
]]> | <%-- <asp:label id="lblchtmsg" width="230px" runat="server" text="<%#Eval(" chat_msgs")%>"=""> --%>
<%#Eval("Chat_msgs")%>
|
<rowstyle backcolor="WhiteSmoke">
<alternatingrowstyle backcolor="#E0E0E0">
|
<asp:timer id="Timer1" runat="server" interval="200" ontick="Timer1_Tick" enabled="True">
<%--<asp:timer id="Timer2" runat="server" ontick="Timer2_Tick" enabled="False" interval="200">
--%>
here is the .cs code
public partial class showmsg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void asUser()
{
string cnt = dbFunctions.getSingleRecord ("select count(*) from ChatMsgs where Chat_id='" + Session["chatid"].ToString()+"'");
if (int.Parse(cnt) > 10)
lbtncomplete.Visible = true;
// DataTable dt = dbFunctions.getTable("select * from ChatMsgs where Chat_id='" + Session["chatid"].ToString() + "' ORDER BY ID ASC");
DataTable dt = dbFunctions.getTable("select * from ChatMsgs where ID in(select TOP 11 ID from ChatMsgs where Chat_id='" + Session["chatid"].ToString() + "' ORDER BY ID DESC) ");
gvmsg.DataSource = dt;
gvmsg.DataBind();
}
public void asAdmin()
{
DataTable dt = dbFunctions.getTable("select * from ChatMsgs where Chat_id='" + Session["chatid"].ToString() + "'");
// DataTable dt = dbFunctions.getTable("select * from ChatMsgs ORDER BY ID DESC ");
gvmsg.DataSource = dt;
gvmsg.DataBind();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
//if (Session["top10"].ToString() == "true")
//asUser();
asAdmin();
}
protected void lbtncomplete_Click(object sender, EventArgs e)
{
//Session["top10"] = "false";
DataTable dt = dbFunctions.getTable("select * from ChatMsgs where Chat_id='" + Session["chatid"].ToString() + "' ORDER BY ID ASC");
// DataTable dt = dbFunctions.getTable("select * from ChatMsgs ORDER BY ID DESC ");
gvmsg.DataSource = dt;
gvmsg.DataBind();
}
}
Please help its really urgent
Thanks in advance
|
|
|
|
|
Use this javascript code after the databind or just before the closing body tage.
var objDiv = document.getElementById("div1");
objDiv.scrollTop = objDiv.scrollHeight;
Use the original 'div id' in place of div1.
The miracle is this--the more we share, the more we have.
|
|
|
|
|
hey gaurav thanks for reply
i was waiting for a reply no body replied i guess its not such atough question
anywaz your solution is not working any other solutions.
i am fed up this problem
hopefuly some one can give a solution(s)
thanks in adavnce
|
|
|
|
|
oh...
It should work...Because it is tested in my porject.
For creating a scroll i used style="overflow:auto" in my div...
Try it again...
The miracle is this--the more we share, the more we have.
|
|
|
|
|
hey gaurav
believe me its not working i tried it ..(many times now)
my chat messages are going down i have drag the vertical scroll bar down to see the messages
the scroll position does not remain at the same position after the timer_tick in update panel fires....
waiting for your reply
Thanks in advance
|
|
|
|
|
also sorry to disturb u alot
u can try my code which i have given in first post
thanks in advance
tc
|
|
|
|
|
hi All,
I am new to dot net...
i am learning it and I am doing my masters project in c# dot net with sql server 2000 backend...
The issue i am having now is...
i am having a gridview, upon selection of one of the rows, the row data is loaded into the textbox and dropdowns, so that when changes are made and update button is hit, the data is updated in the backend...
all works fine except for the update issue is with postback but i dont know how to do that... pls help... giving all the codes below...
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class scenarios : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("...;");
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
SqlDataAdapter da;
common obj = new common();
string sql;
string s;
protected void Page_Load(object sender, EventArgs e)
{
Session["projid"] = "12345";
Session["projname"] = "ProjectA";
if (!IsPostBack)
{
pid.Text = Session["projid"].ToString();
pname.Text = Session["projname"].ToString();
sql = "select * from scenarios where pid = '" + Session["projid"].ToString() + "'";
da = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
da.Fill(dt);
int prowct = dt.Rows.Count;
if (prowct == 0)
{
btnadd.Visible = true;
btnupdate.Visible = false;
GridView1.DataBind();
}
else
{
btnadd.Visible = true;
btnupdate.Visible = false;
GridView1.DataBind();
}
}
}
protected void btnadd_Click(object sender, EventArgs e)
{
con.Open();
sql = "Insert into scenarios values ('" + pid.Text + "','" + pname.Text + "','" + tbcat.Text + "','" + tbscenario.Text + "','" + ddlprob.SelectedValue.ToString() + "','" + ddlprob.SelectedItem.Text + "','" + ddlimpact.SelectedValue.ToString() + "','" + ddlimpact.SelectedItem.Text + "','" + tbmitig.Text + "')";
cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
obj.msgbox("Values are inserted");
con.Close();
clearall();
GridView1.DataBind();
}
public void clearall()
{
tbcat.Text = "";
tbscenario.Text = "";
ddlprob.ClearSelection();
ddlimpact.ClearSelection();
tbmitig.Text = "";
}
protected void btnreset_Click(object sender, EventArgs e)
{
clearall();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
btnadd.Visible = false;
btnupdate.Visible = true;
s = GridView1.SelectedValue.ToString();
sql = "select * from scenarios where ID = '" + s + "'";
con.Open();
cmd = new SqlCommand(sql, con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
tbcat.Text = dr[3].ToString();
tbscenario.Text = dr[4].ToString();
ddlprob.SelectedIndex = int.Parse(dr[5].ToString());
ddlimpact.SelectedIndex = int.Parse(dr[7].ToString());
tbmitig.Text = dr[9].ToString();
}
con.Close();
}
protected void btnupdate_Click(object sender, EventArgs e)
{
//cmd.Connection = con;
con.Open();
sql = "update scenarios set discateg = '" + tbcat.Text + "', disscenario= '" + tbscenario.Text + "', probval = '" + ddlprob.SelectedValue.ToString() + "', prob = '" + ddlprob.SelectedItem.Text + "', impactval = '" +ddlimpact.SelectedValue.ToString() + "', impact = '" + ddlimpact.SelectedItem.Text + "', mitig = '" + tbmitig.Text + "' where ID= '" +s + "'";
cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
obj.msgbox("Values are updated");
con.Close();
clearall();
GridView1.DataBind();
}
}
-----------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="scenarios.aspx.cs" Inherits="scenarios" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
text-align: right;
}
</style>
</head>
<body style="font-family: Verdana; font-size: x-small">
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td>
</td>
<td class="style2">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
Project Name:</td>
<td>
<asp:Label ID="pname" runat="server"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
</td>
<td>
<br />
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
Project ID:</td>
<td>
<asp:Label ID="pid" runat="server"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
Category:</td>
<td>
<asp:TextBox ID="tbcat" runat="server" Width="183px" Font-Names="Verdana"
Font-Size="X-Small"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
Disaster Scenario:</td>
<td>
<asp:TextBox ID="tbscenario" runat="server" Height="62px" Width="183px"
Font-Names="Verdana" Font-Size="X-Small"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
Probability:</td>
<td>
<asp:DropDownList ID="ddlprob" runat="server" Font-Names="Verdana"
Font-Size="X-Small">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">Low</asp:ListItem>
<asp:ListItem Value="2">Medium</asp:ListItem>
<asp:ListItem Value="3">High</asp:ListItem>
</asp:DropDownList>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
Impact:</td>
<td>
<asp:DropDownList ID="ddlimpact" runat="server" Font-Names="Verdana"
Font-Size="X-Small">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">High</asp:ListItem>
<asp:ListItem Value="2">Medium</asp:ListItem>
<asp:ListItem Value="3">Low</asp:ListItem>
</asp:DropDownList>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
Mitigation:</td>
<td>
<asp:TextBox ID="tbmitig" runat="server" Height="62px" Width="183px"
Font-Names="Verdana" Font-Size="X-Small"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2">
<asp:Button ID="btnupdate" runat="server" Height="20px"
onclick="btnupdate_Click" Text="Update" Width="50px" />
<asp:Button ID="btnadd" runat="server" Height="20px" Text="Add" Width="50px"
onclick="btnadd_Click" />
</td>
<td>
&n bsp;
<asp:Button ID="btnreset" runat="server" Height="20px" Text="Reset"
Width="50px" onclick="btnreset_Click" />
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td class="style2" colspan="2">
<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" DataKeyNames="ID" DataSourceID="SqlDataSource1"
onselectedindexchanged="GridView1_SelectedIndexCha nged"
style="text-align: left">
<Columns>
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:bcpertConnectionString %>"
SelectCommand="SELECT * FROM [scenarios] WHERE ([pid] = @pid)">
<SelectParameters>
<asp:SessionParameter Name="pid" SessionField="projid" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
------------------------
table creation code:
CREATE TABLE [dbo].[scenarios] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[pid] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[pname] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[discateg] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[disscenario] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[prob] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[impact] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[mitig] [varchar] (300) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
|
|
|
|
|
use formview and use its edit template to updata the data.
code is below.i am suggest this is bcos its widely use in field. u can use your method for which i put the btn edit event below.
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "editbtn")
{
frm_emp.ChangeMode(FormViewMode.Edit);//frm_emp is the name of formview
ViewState["id"] = e.CommandArgument.ToString();
//com.CommandText = "select * from emp_data where id like '" + e.CommandArgument.ToString() + "%'";
com = new SqlCommand();
com.CommandText = "select_record_id";//use above query
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@eid", e.CommandArgument.ToString());
com.Connection = con;
ds = new DataSet();
adp = new SqlDataAdapter(com);
adp.Fill(ds);
frm_emp.Visible = true;
frm_emp.DataSource = ds.Tables[0];
frm_emp.DataBind();
protected void btnedit_Click(object sender, EventArgs e)//event on update button.
{
try
{
con.Open();
com = new SqlCommand();
com.Connection = con;
//com.CommandText = "select * from emp_data where name=('" + ((TextBox)frm_emp.FindControl("txtenm")).Text + "') and id<>'" + ViewState["id"].ToString() + "'";
com.CommandText = "select_record_name_id";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@enm",((TextBox)frm_emp.FindControl("txtenm")).Text);
com.Parameters.AddWithValue("@eid",ViewState["id"].ToString());
ds = new DataSet();
adp = new SqlDataAdapter(com);
adp.Fill(ds);
if (ds.Tables[0].Rows.Count>0)
{
Response.Write("name already exist");
}
else
{
com = new SqlCommand();
com.Connection = con;
//com.CommandText = "update emp_data set id='" + ((TextBox)frm_emp.FindControl("txtid")).Text + "',name='" + ((TextBox)frm_emp.FindControl("txtenm")).Text + "',designation='" + ((TextBox)frm_emp.FindControl("txtdesignation")).Text + "',jdate='" + ((TextBox)frm_emp.FindControl("txtjdate")).Text + "' where id='" + ViewState["id"].ToString() + "'";
com.CommandText = "update_record";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@eid", ((TextBox)frm_emp.FindControl("txtid")).Text);
com.Parameters.AddWithValue("@ename", ((TextBox)frm_emp.FindControl("txtenm")).Text);
com.Parameters.AddWithValue("@desg", ((TextBox)frm_emp.FindControl("txtdesignation")).Text);
com.Parameters.AddWithValue("@ejdate", ((TextBox)frm_emp.FindControl("txtjdate")).Text);
com.Parameters.AddWithValue("eidcheck", ViewState["id"].ToString());
com.ExecuteNonQuery();
con.Close();
//com = new SqlCommand("select * from emp_data");
/*com = new SqlCommand();
com.CommandText = "selectrecord";
com.CommandType = CommandType.StoredProcedure;
com.Connection = con;
ds = new DataSet();
adp = new SqlDataAdapter(com);
adp.Fill(ds);
grdemp.DataSource = ds;
grdemp.DataBind();*/
binddata();
Response.Write("record edited succesfully");
grdemp.Visible = true;
frm_emp.Visible = false;
//con.Close();
}
}
catch (Exception E)
{
Response.Write("record not edited");
}
}
}
|
|
|
|
|
i have one master page which contain the menu and its menuitem.
i have to access the menu or menuitem in my other .cs file(it has master page)?
how can i access this?
|
|
|
|
|
If what you asking is how to access controls in a Master Page from code-behind...
MyMasterPage myMaster = (MyMasterPage)this.Master;
string ImgStr = "images/test.gif";
myMaster.setMasterHeaderImages(ImgStr);
myMaster.Page.Title = "Test Page Title";
Check http://aspadvice.com/blogs/kiran/archive/2005/11/27/14016.aspx[^] here.
|
|
|
|
|
i have menu in master page and i have to access it in other cs(eg. default.aspx.cs) file.
|
|
|
|
|
ContentPlaceHolder content;
content = Master.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
for ex
TextBox txt=content.FindControl("txtName") as TextBox;
Raju.M
|
|
|
|
|
how can we access outlook address book in an windows application.
i have done this
private Outlook.Application objoutlook = null;
private Outlook.NameSpace objNamespace = null;
private Outlook.MAPIFolder objFolder = null;
Outlook.ApplicationClass appOut = new Outlook.ApplicationClass();
Outlook.SelectNamesDialog oSND = appOut.Session.GetSelectNamesDialog();
Outlook.AddressList x = oSND.InitialAddressList;
foreach (Outlook.AddressEntry y in x.AddressEntries)
{
if (y.AddressEntryUserType ==
Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry)
{
Outlook.ExchangeUser u = y.GetExchangeUser();
string t = u.GetContact().FullName;
string L = u.GetContact().BusinessAddressCity;
}
}
this coding i did for office 2007 but i am not getting for 2003 office outlook .
Thanks
|
|
|
|
|
I have a usercontrol, which takes datatable as a property and creates dynamic dataentry facility (Add/Edit) in gridview.
Parent control class I have a gridview, whosed columns are templated columns which I create dynamically:
TemplateField tf = new TemplateField();
tf.HeaderTemplate =
new DynamicallyTemplatedGridViewHandler(ListItemType.Header,
dt.Columns[i].ColumnName, dt.Columns[i].DataType.Name);
tf.ItemTemplate =
new DynamicallyTemplatedGridViewHandler(ListItemType.Item,
dt.Columns[i].ColumnName, dt.Columns[i].DataType.Name);
tf.EditItemTemplate =
new DynamicallyTemplatedGridViewHandler(ListItemType.EditItem,
dt.Columns[i].ColumnName, dt.Columns[i].DataType.Name);
I have used the following class
class DynamicallyTemplatedGridViewHandler : ITemplate
and created methods
public void InstantiateIn(System.Web.UI.Control Container)
{
switch (ItemType)
{
...
...
...
case ListItemType.EditItem:
switch (InfoType)
{
...
...
...
case "DateTime":
pages_control_DateBox field_datebox = new pages_control_DateBox();
field_datebox.ID = FieldName;
if ((int)new Page().Session["InsertFlag"] == 0)
field_datebox.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_datebox);
break;
...
...
...
}
private void OnDataBinding(Object sender, EventArgs e)
{
object bound_value_obj = null;
Control ctrl = (Control)sender;
IDataItemContainer data_item_container = (IDataItemContainer)ctrl.NamingContainer;
bound_value_obj = DataBinder.Eval(data_item_container.DataItem, FieldName);
switch (ItemType)
{
...
...
...
case ListItemType.EditItem:
switch (InfoType)
{
...
...
...
case "DateTime":
pages_control_DateBox field_dateBox = (pages_control_DateBox)sender;
field_dateBox.Text = "";
field_dateBox.CalendarDate = bound_value_obj.ToString();
break;
...
...
...
}
Now, in case of a DateTime field, for edit template, I use my own user control "DateBox". Now, when I click on the edit icon on my grid, I get the following error:
Object reference not set to an instance of an object.
Someone please help.
Do let me know, in case more information is required.
|
|
|
|
|
is sender NULL when case "DateTime" ?
Put a breakpoint on that line, and see if sender is instance of something.
Let me know,
Calin
|
|
|
|
|
sender is not null.
Till binding every step works fine, but as soon as it wanted to display the DateBox, it is not able to.
Point is I have this GridUserControl and inside it, I want to bind this DateUserControl. I guess I have to make some change in the code of DateUserControl so that it can instantiate properly.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class pages_control_DateBox : System.Web.UI.UserControl
{
private void Page_Load(object sender, System.EventArgs e)
{
string scriptStr = "javascript:return popUpCalendar(this, document.getElementById('" + getClientID() + @"'), 'mm/dd/yyyy', '__doPostBack(\'" + getClientID() + @"\')')";
imgCalendar.Attributes.Add("onclick", scriptStr);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
public string getClientID()
{
return txt_Date.ClientID;
}
public string CalendarDate
{
get
{
return txt_Date.Text;
}
set
{
txt_Date.Text = value;
}
}
}
I am not sure, what to change.
|
|
|
|
|