|
|
|
Hi Everybody,
Sorry for the very basic question, I'm totally new to ASP.NET. My task is to write a simple user control to be talking with SharePoint. The problem I have is understanding communication with the Datagrid. At hte moment where I think I must be geeting the contents of the cells on grid I'm getting Argument.Out.OfRAnge Exception. I'm obviously doing something wrong, but my Win-form experience doesn't tell me what. Any help is very much appreciated. Thanks
In the following code I'm able to display the contents of the DataTable, then add a new row to the table, display it. But when I click on the "update" button on the grid to display the contents of the cells in Labels, "Index Out of range"exception is thrown.
Code:
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
Fill();
Bind();
}
}
#region Bind
private void Fill()
{
fieldList = new ArrayList();
fieldList.Add("Field1");
fieldList.Add("Field2");
missGridTable = new DataTable();
string error = string.Empty;
SPCom sp = new SPCom();
missGridTable = sp.BindWithFieldList(web,"Test List",fieldList,error); //this succesfully populates the datatable
}
private void Bind()
{
missionGrid.DataSource = missGridTable;
missionGrid.AutoGenerateColumns=false;
missionGrid.DataBind();
foreach(DataColumn c in missGridTable.Columns)
{
missionGrid.Columns.Add(CreateBoundColumn(c));
}
missionGrid.DataBind();
}
private BoundColumn CreateBoundColumn(DataColumn c)
{
BoundColumn column = new BoundColumn();
column.DataField = c.ColumnName;
column.HeaderText = c.ColumnName.Replace("_"," ");
column.DataFormatString ="";
return column;
}
#endregion Bind
private void InsertEmpty()
{
missGridTable.Rows.InsertAt(missGridTable.NewRow(), 0);
}
private void add_Click(object sender, System.EventArgs e)
{
try
{ // inserting
missionGrid.EditItemIndex = 0;
// modify text
EditCommandColumn ecc =
(EditCommandColumn) missionGrid.Columns[0];
ecc.UpdateText = "Insert";
// fill table, insert empty row, bind to datagrid
Fill();
InsertEmpty();
Bind();
}
catch (Exception Ex)
{
Label1.Text = Ex.ToString();
}
}
# region grid click parser
private void grid_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// stop editing
missionGrid.EditItemIndex = -1;
switch (e.CommandName)
{
case "Update": // this causes an exception
{
try
{
TableCell cellField1 = e.Item.Cells[1];
TableCell cellField2 = e.Item.Cells[2];
string field1 = cellField1.Text;
string field2 = cellField2.Text;
Label1.Text = "-----" + field2;
Label1.Text = "asasdsadasd";
}
catch (Exception ex)
{
Label1.Text = ex.ToString();
}
|
|
|
|
|
HI,
Exactly where you get the error?
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Hi,
I'm getting an error here, when I'm trying to access the fields in the DataGrid
The exception is index out of range
try
{
TableCell cellField1 = e.Item.Cells[1];
TableCell cellField2 = e.Item.Cells[2];
string field1 = cellField1.Text;
string field2 = cellField2.Text;
Label1.Text = "-----" + field2;
}
thanks
-- modified at 6:55 Monday 7th May, 2007
|
|
|
|
|
Hi,
The solution I m giving you is as per my consideration because I am not aware of the term "SPCom" in your code.
As per your code your datatable is having only 2 columns "Field1" and "Field2". So the datagrid will have only 2 columns [0] and [1] when u bind it with the table.
In try block you are trying to access cell[2] which is actually 3rd column of the datagrid which does not exist. I think this is why you r getting this exception.
If I m correct then the solution is to have proper number of columns in your grid so that u can access them in your code.
I hope this will help you.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Hello,
Is there a way we can make a Cross Tab in GridView using ASP.NET 2.0.
There is a simple workarund available that the SQL statement can be restructred so that it returns cross tab view however this is not something which I want.
Thanks
|
|
|
|
|
with the below code the program runs without any error. still no mails are received at the client side.
my code is as follows:
----------------------
using System.Net.Mail;
protected void btnSendMail_Click(object sender, EventArgs e)
{
SmtpClient mysmtpClient = new SmtpClient();
mysmtpClient.Host = "localhost";
mysmtpClient.UseDefaultCredentials = true;
MailMessage jum = new MailMessage();
MailAddress mfrom = new MailAddress("me@myweb.com", "me");
mysmtpClient.Port = 25;
jum.From = mfrom;
jum.To.Add("client1@myweb.com");
jum.To.Add("client2@myweb.com.com");
jum.Subject = "subject and object";
jum.Body = "hello fellow what r u doing";
jum.IsBodyHtml = false;
mysmtpClient.Send(jum);
Label1.Text = "mail sent successfully";
}
vlm
|
|
|
|
|
use the namespace System.Web.Mail and try ......
MailMessage mail=new MailMessage();
mail.To = "rahul@microsoft.com";//to address
mail.From = "xxx@xx.com"; //give any address
mail.Subject = "Issue Fixed"; //Subject of mail
mail.Body = "The issue has been fixed"; //Body of mail
SmtpMail.SmtpServer = "10.54.1.1";//Use this if u use proxy server for internet
SmtpMail.Send(mail);
|
|
|
|
|
hi,
im using asp.net2.0. i want to print the contents of a datagrid. is there any in built techniques.
I am usnig paging but need the entire data of the datagrid
thanks in advance
arun
|
|
|
|
|
|
hi,
thank u for ur help...it describes how to do it in a desktop application, im seeking help in the case of the asp.net
arun
|
|
|
|
|
Please guide me how use if condition in datagrid templates.
I have table in data is of threetype
status is field heading name.
status
Inkitchen
Ready
Serve
i want to show data in datagrid templete in different color in one coloum
like this
Inkitchen should be in red color
Ready should be in ble color
serve should be in black color
i using lable or link button
suhail shahab
|
|
|
|
|
Hi,
If you r using labels to display the status then you can check for the Text Property of them in the ItemDataBound event of the datagrid and change to color of lable there.
The following code may help you.
protected void dg_ItemDataBound(object sender, DatagridItemEventArgs e)
{
if(e.Item.ItemTyep == ListItemType.Item || e.Item.ItemType.AlternateItem)
{
Label lbl = (Label)(e.Item.FindControl("lblStatus");
if(lbl.Text == "Inkitchen")
lbl.ForeColor = Color.Red;
else if(lbl.Text == "Ready")
lbl.ForeColor = Color.Blue;
else if(lbl.Text == "Serve")
lbl.ForeColor = Color.Black;
}
}
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
salam sir
I am vvvvvery happy of ur guidance and sending code.u have solved my problem thanks sir.
Sohial shahab
|
|
|
|
|
Hi,
You r most welcome.
Also please dont call me sir.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Guyz,
how can Clear Browser's Cache after hitting Logout Button?
If I press back button after logout, it's going to previous page.
How can block this ?
Expecting ur replys....
thank you
Mohamed Nazeem
|
|
|
|
|
Try this..in your Page_load()
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Koushik
|
|
|
|
|
Hi,
Still it's not working. If i press back button, again it's going to previous Page. Tell me how can i block this ?
Mohamed Nazeem
Software Engineer
Bangalore
|
|
|
|
|
Hi,
Can You try this piece of code inside your Page_Load
Response.Buffer = True
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1D)
Response.Expires = -1500
Response.CacheControl = "no-cache"
Sherin Iranimose
|
|
|
|
|
My question is very simple, Suppose I have two aspx pages;Page1 and Page2. When I redirect from Page1 to Page2, Page2 should load. But if I directly specify the url of Page2, it should not load. How can I do that without using any Session or Cookies.
Thanks
|
|
|
|
|
Search for the authentication in asp.net
you can do that by adding some seetings in web.cofig
<br />
<authentication mode="Forms"><br />
<forms loginUrl="Logon.aspx" name=".ASPXFORMSAUTH"><br />
</forms><br />
</authentication><br />
<br />
Its better to understand first and then use it
so take help from MSDN or google for "Forms Authentication Provider
"
Thanks and Regards
Sandeep
If you want something you never had,
do something you have never done!
|
|
|
|
|
I have an existing report I created in Crystal 10. I would like to display this in an asp.net page. It has no parameters simple report. I have also included the .rpt file into the VS project.
How do i bind the report to the report viewer?
Thanks
|
|
|
|
|
hi,
i want to import excel sheet datas into mysql table using C# code. anybody please help me with proper code.
Regards
Vijay.
|
|
|
|
|
Hi,
I am trying to kill process from task manager using "End Process" in "Processes" tab. But I tried to get the handle / PID of the process that I have selected to terminat. I would like to know how to get the handle / PID of the process that I am trying to terminate.
I tried to use TerminateProcess API to handle this. But I am not able to get handle for the killing process (e.g. winword.exe).
Anything on this will help.
Thanks
SNI
|
|
|
|