Click here to Skip to main content
15,943,479 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: mouseclick Pin
Sebastian T Xavier7-May-07 0:10
Sebastian T Xavier7-May-07 0:10 
GeneralRe: mouseclick Pin
enjoycrack7-May-07 0:38
enjoycrack7-May-07 0:38 
GeneralRe: mouseclick Pin
Sebastian T Xavier7-May-07 1:06
Sebastian T Xavier7-May-07 1:06 
GeneralRe: mouseclick Pin
enjoycrack7-May-07 1:12
enjoycrack7-May-07 1:12 
GeneralRe: mouseclick Pin
Sebastian T Xavier7-May-07 1:19
Sebastian T Xavier7-May-07 1:19 
GeneralRe: mouseclick Pin
enjoycrack7-May-07 2:37
enjoycrack7-May-07 2:37 
GeneralRe: mouseclick Pin
Sebastian T Xavier7-May-07 2:47
Sebastian T Xavier7-May-07 2:47 
QuestionProblem with DataGrid Pin
zamiran6-May-07 23:04
zamiran6-May-07 23:04 
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();

}

QuestionRe: Problem with DataGrid Pin
Chetan Ranpariya6-May-07 23:21
Chetan Ranpariya6-May-07 23:21 
GeneralRe: Problem with DataGrid [modified] Pin
zamiran6-May-07 23:27
zamiran6-May-07 23:27 
GeneralRe: Problem with DataGrid Pin
Chetan Ranpariya7-May-07 21:22
Chetan Ranpariya7-May-07 21:22 
QuestionCross Tab GridView Pin
APDevelop6-May-07 22:47
APDevelop6-May-07 22:47 
QuestionSend mail to microsoft exchange 2007- asp.net 2.0 Pin
vlmlnt6-May-07 22:07
vlmlnt6-May-07 22:07 
AnswerRe: Send mail to microsoft exchange 2007- asp.net 2.0 Pin
Rahul Babu6-May-07 22:29
Rahul Babu6-May-07 22:29 
QuestionPrint the contents of a DataGrid Pin
arun rajappan6-May-07 22:00
arun rajappan6-May-07 22:00 
AnswerRe: Print the contents of a DataGrid Pin
Spunky Coder6-May-07 22:29
Spunky Coder6-May-07 22:29 
GeneralRe: Print the contents of a DataGrid Pin
arun rajappan7-May-07 0:09
arun rajappan7-May-07 0:09 
Questionpleas guide me how we change the color of lable or link buttton in datagird temple programmatically Pin
Suhail Shahab6-May-07 21:55
Suhail Shahab6-May-07 21:55 
AnswerRe: pleas guide me how we change the color of lable or link buttton in datagird temple programmatically Pin
Chetan Ranpariya6-May-07 22:52
Chetan Ranpariya6-May-07 22:52 
GeneralRe: pleas guide me how we change the color of lable or link buttton in datagird temple programmatically Pin
Suhail Shahab7-May-07 1:53
Suhail Shahab7-May-07 1:53 
GeneralRe: pleas guide me how we change the color of lable or link buttton in datagird temple programmatically Pin
Chetan Ranpariya7-May-07 2:17
Chetan Ranpariya7-May-07 2:17 
QuestionClear Browser's Cache after hitting Logout Button? Pin
md Nazeem6-May-07 21:39
md Nazeem6-May-07 21:39 
AnswerRe: Clear Browser's Cache after hitting Logout Button? Pin
Spunky Coder6-May-07 22:13
Spunky Coder6-May-07 22:13 
GeneralRe: Clear Browser's Cache after hitting Logout Button? Pin
md Nazeem6-May-07 23:09
md Nazeem6-May-07 23:09 
AnswerRe: Clear Browser's Cache after hitting Logout Button? Pin
Sherin Iranimose8-May-07 0:49
Sherin Iranimose8-May-07 0:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.