|
I don't think this class is exactly for you - you may have to modify it or better have a better query that does the joining for you
however to get the 'ID' field then you should just be able to use the field name like this
string myID = ((DataRowView) container.DataItem)["ID"].ToString();
Technically speaking the dictionary would define Visual Basic users as programmers. But here again, a very generalized, liberal definition is being employed and it's wrong - just plain wrong - Tom Archer 5/12/02
|
|
|
|
|
Please can you explaim to me exactly how add a simple column to a datagrid. In fact, when I add a column to my datagrid, she appaers at the left and I would like show it at the right.
Thanks a lot
|
|
|
|
|
how are you adding the column to the grid?
columns are displayed (I think) in order that they are added to the Columns collection
Technically speaking the dictionary would define Visual Basic users as programmers. But here again, a very generalized, liberal definition is being employed and it's wrong - just plain wrong - Tom Archer 5/12/02
|
|
|
|
|
I have got a datagrid and in that I have got list of values with checkboxes,I wanted to get the values from list into the a label when ever I checked a particular checkbox or multiple checkboxes.
thanks,
Regards,
Syed
|
|
|
|
|
The article I have shown is probably unsuitable for this task as the checkboxes in this example are bound to a field. You will probably have to make your own column with checkboxes and then you will have to process their click events server side (if that is where you wish to move value from list into the label). else you may have to use javascript to do the task.
Technically speaking the dictionary would define Visual Basic users as programmers. But here again, a very generalized, liberal definition is being employed and it's wrong - just plain wrong - Tom Archer 5/12/02
|
|
|
|
|
I have looked everywhere for answers on how to get to the CheckedChanged event of a chackbox within a datagrid. You have done it and I'm too new to C# and ASP.NET to understand all that you have done.
Is there an easy way to get to the CheckedChanged event and still have access to e.Item.ItemIndex within the datagrid so I can update that one column when it is changed?
"RecursioN" is a lot like "RecursioN"
|
|
|
|
|
Chadrick Mahaffey wrote:
I have looked everywhere for answers on how to get to the CheckedChanged event of a chackbox within a datagrid. You have done it and I'm too new to C# and ASP.NET to understand all that you have done.
There isn't a CheckedChanged event in a datagrid I added this event to show how it could be done as an example to an earlier poster.
Chadrick Mahaffey wrote:
Is there an easy way to get to the CheckedChanged event and still have access to e.Item.ItemIndex within the datagrid so I can update that one column when it is changed?
you could possibly modify the code to alter/replace the arguments at the checkitem layer and change the eventargs to be DataGridCommandEventArgs or you could use a unique field in the container like I did
Technically speaking the dictionary would define Visual Basic users as programmers. But here again, a very generalized, liberal definition is being employed and it's wrong - just plain wrong - Tom Archer 5/12/02
|
|
|
|
|
is there a reason that this:
public CheckBoxItem(bool editable)<br />
{<br />
readOnly = (editable==true)?false:true;<br />
}
couldn't be this?
public CheckBoxItem(bool editable)<br />
{<br />
readOnly = !editable;<br />
}
-John
|
|
|
|
|
non at all - I tend to do that for readability
It's probably not optimised I should have a look at the IL and see what it makes of it I suppose
If I was doing optimsed code I woulde use the second form but when I am writing articles I tend to go for readability rather than optimisation
Technically speaking the dictionary would define Visual Basic users as programmers. But here again, a very generalized, liberal definition is being employed and it's wrong - just plain wrong - Tom Archer 5/12/02
|
|
|
|
|
I just wanted to say cheers mate!
Your article was just the answer I was looking for, and to my knowlege it's the only one of it's kind on the net at the mo.
Many thanks again!
Tal
|
|
|
|
|
your welcome
tallal_garghouti@hotmail.com wrote:
Your article was just the answer I was looking for, and to my knowlege it's the only one of it's kind on the net at the mo.
I do try and not repeat what has already been done
Technically speaking the dictionary would define Visual Basic users as programmers. But here again, a very generalized, liberal definition is being employed and it's wrong - just plain wrong - Tom Archer 5/12/02
|
|
|
|
|
As I see the cells of the table have no vertical alignment. How do you apply a vertical alignment to this control. Without vertical alignment this control practically has no use for projects other than tests.
|
|
|
|
|
tester1 wrote:
As I see the cells of the table have no vertical alignment. How do you apply a vertical alignment to this control.
Can you explain what you mean? If you mean the alignment of the checkbox then you just have to modify the code.
tester1 wrote:
Without vertical alignment this control practically has no use for projects other than tests.
I never said this was an out of the box control that would do everything that anyone would want. It is a sample showing how you could do something - if it doesn't do what you want then change it - or pay someone to change it for you.
As for no practical use - I use it and its modified brethren every day.
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
I found a way to do that. However I was hoping that this control would have the ability to present data in a decent way since the control it's self is easy and convenient to use. I understand that coders do not have much of a vision for GUI but I expect a little more from MSFT and a $2400 Visual Studio .Net Oh I noticed the cliche on the bottom of your message. I felt sorry for you.
|
|
|
|
|
ItemStyle-VerticalAlign="top"
|
|
|
|
|
Anonymous wrote:
I understand that coders do not have much of a vision for GUI
It's all I do - but the code presented was really to show how to make your own column be it a checkbox or a combobox or even radio buttons - if you want a commercial product then you'll have to pay - my clients pay lots and get well supported all singing and dancing code to their specs.
Anonymous wrote:
but I expect a little more from MSFT and a $2400 Visual Studio .Net
I don't work for MSFT and if you paid that much you were robbed - I paid that for 2 years of MSDN and that's in the UK
Anonymous wrote:
Oh I noticed the cliche on the bottom of your message. I felt sorry for you.
cliche?
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
hi
I tried your CheckBoxColumn in a my DataGrid, by adding it with
DataGrid1.Columns.Add(objColumn)
before the DataGrid1.DataBind()
If I place this code inside
if (!Page.IsPostBack){}
and I click on a button contained in the webform, to generate a postback....the checkbox column disappears. I think so that the column doesn't save its viewstate.
Is it wrong?
Thank you.
Bye
|
|
|
|
|
I'd do it like this
DataGrid1.Columns.Add(objColumn);
if (!Page.IsPostBack)
{
...
DataGrid1.DataBind()
}
or do the Add ing earlier
I do mine in the OnInit handler just after calling InitializeComponent
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku .
|
|
|
|
|
 no... it's being not working.
Here my code:
<br />
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
CheckBoxColumn checkCol = new CheckBoxColumn();<br />
checkCol.HeaderText = "Boolean Field (Editable)";<br />
checkCol.DataField = "Discontinued";<br />
DataGrid1.Columns.Add(checkCol);<br />
<br />
if (!Page.IsPostBack)<br />
{<br />
BindGrid();<br />
}<br />
}<br />
<br />
<br />
private void BindGrid()<br />
{<br />
sqlDataAdapter1.Fill(dataSet11);<br />
DataGrid1.DataBind();<br />
}<br />
<br />
override protected void OnInit(EventArgs e)<br />
{<br />
InitializeComponent();<br />
base.OnInit(e);<br />
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_SwitchViewMode);<br />
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_SwitchViewMode);<br />
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);<br />
}<br />
private void DataGrid1_SwitchViewMode(object sender, DataGridCommandEventArgs e)<br />
{<br />
Label1.Text = "";<br />
<br />
switch (e.CommandName)<br />
{<br />
case "Edit":<br />
DataGrid1.EditItemIndex = e.Item.ItemIndex;<br />
break;<br />
default:<br />
DataGrid1.EditItemIndex = -1;<br />
break;<br />
}<br />
<br />
BindGrid();<br />
}<br />
<br />
private void DataGrid1_UpdateCommand(object sender, DataGridCommandEventArgs e)<br />
{<br />
CheckBox objCheck = (CheckBox)e.Item.Cells[5].Controls[0];<br />
Label1.Text = "Il nuovo valore per la riga con ID " + DataGrid1.DataKeys[e.Item.ItemIndex].ToString()<br />
+ " è " + objCheck.Checked.ToString();<br />
<br />
DataGrid1.EditItemIndex = -1;<br />
BindGrid();<br />
}<br />
thank you very much for the quick response.
ByelierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued) VALUES (@ProductName, @SupplierID, @CategoryID, @QuantityPerUnit, @UnitPrice, @UnitsInStock, @UnitsOnOrder, @ReorderLevel, @Discontinued); SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued FROM Products WHERE (ProductID = @@IDENTITY)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductName", System.Data.SqlDbType.NVarChar, 40, "ProductName"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@SupplierID", System.Data.SqlDbType.Int, 4, "SupplierID"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CategoryID", System.Data.SqlDbType.Int, 4, "CategoryID"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@QuantityPerUnit", System.Data.SqlDbType.NVarChar, 20, "QuantityPerUnit"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UnitPrice", System.Data.SqlDbType.Money, 8, "UnitPrice"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UnitsInStock", System.Data.SqlDbType.SmallInt, 2, "UnitsInStock"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UnitsOnOrder", System.Data.SqlDbType.SmallInt, 2, "UnitsOnOrder"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ReorderLevel", System.Data.SqlDbType.SmallInt, 2, "ReorderLevel"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Discontinued", System.Data.SqlDbType.Bit, 1, "Discontinued"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE Products SET ProductName = @ProductName, SupplierID = @SupplierID, CategoryID = @CategoryID, QuantityPerUnit = @QuantityPerUnit, UnitPrice = @UnitPrice, UnitsInStock = @UnitsInStock, UnitsOnOrder = @UnitsOnOrder, ReorderLevel = @ReorderLevel, Discontinued = @Discontinued WHERE (ProductID = @Original_ProductID) AND (CategoryID = @Original_CategoryID OR @Original_CategoryID IS NULL AND CategoryID IS NULL) AND (Discontinued = @Original_Discontinued) AND (ProductName = @Original_ProductName) AND (QuantityPerUnit = @Original_QuantityPerUnit OR @Original_QuantityPerUnit IS NULL AND QuantityPerUnit IS NULL) AND (ReorderLevel = @Original_ReorderLevel OR @Original_ReorderLevel IS NULL AND ReorderLevel IS NULL) AND (SupplierID = @Original_SupplierID OR @Original_SupplierID IS NULL AND SupplierID IS NULL) AND (UnitPrice = @Original_UnitPrice OR @Original_UnitPrice IS NULL AND UnitPrice IS NULL) AND (UnitsInStock = @Original_UnitsInStock OR @Original_UnitsInStock IS NULL AND UnitsInStock IS NULL) AND (UnitsOnOrder = @Original_UnitsOnOrder OR @Original_UnitsOnOrder IS NULL AND UnitsOnOrder IS NULL); SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued FROM Products WHERE (ProductID = @ProductID)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductName", System.Data.SqlDbType.NVarChar, 40, "ProductName"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@SupplierID", System.Data.SqlDbType.Int, 4, "SupplierID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CategoryID", System.Data.SqlDbType.Int, 4, "CategoryID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@QuantityPerUnit", System.Data.SqlDbType.NVarChar, 20, "QuantityPerUnit"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UnitPrice", System.Data.SqlDbType.Money, 8, "UnitPrice"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UnitsInStock", System.Data.SqlDbType.SmallInt, 2, "UnitsInStock"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UnitsOnOrder", System.Data.SqlDbType.SmallInt, 2, "UnitsOnOrder"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ReorderLevel", System.Data.SqlDbType.SmallInt, 2, "ReorderLevel"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Discontinued", System.Data.SqlDbType.Bit, 1, "Discontinued"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProductID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CategoryID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CategoryID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Discontinued", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Discontinued", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProductName", System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductName", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_QuantityPerUnit", System.Data.SqlDbType.NVarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "QuantityPerUnit", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ReorderLevel", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ReorderLevel", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_SupplierID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "SupplierID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UnitPrice", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UnitPrice", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UnitsInStock", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UnitsInStock", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UnitsOnOrder", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UnitsOnOrder", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.Int, 4, "ProductID"));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM Products WHERE (ProductID = @Original_ProductID) AND (CategoryID = @Original_CategoryID OR @Original_CategoryID IS NULL AND CategoryID IS NULL) AND (Discontinued = @Original_Discontinued) AND (ProductName = @Original_ProductName) AND (QuantityPerUnit = @Original_QuantityPerUnit OR @Original_QuantityPerUnit IS NULL AND QuantityPerUnit IS NULL) AND (ReorderLevel = @Original_ReorderLevel OR @Original_ReorderLevel IS NULL AND ReorderLevel IS NULL) AND (SupplierID = @Original_SupplierID OR @Original_SupplierID IS NULL AND SupplierID IS NULL) AND (UnitPrice = @Original_UnitPrice OR @Original_UnitPrice IS NULL AND UnitPrice IS NULL) AND (UnitsInStock = @Original_UnitsInStock OR @Original_UnitsInStock IS NULL AND UnitsInStock IS NULL) AND (UnitsOnOrder = @Original_UnitsOnOrder OR @Original_UnitsOnOrder IS NULL AND UnitsOnOrder IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProductID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CategoryID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CategoryID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Discontinued", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Discontinued", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProductName", System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductName", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_QuantityPerUnit", System.Data.SqlDbType.NVarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "QuantityPerUnit", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ReorderLevel", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ReorderLevel", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_SupplierID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "SupplierID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UnitPrice", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UnitPrice", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UnitsInStock", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UnitsInStock", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UnitsOnOrder", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UnitsOnOrder", System.Data.DataRowVersion.Original, null));
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Products", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("ProductID", "ProductID"),
new System.Data.Common.DataColumnMapping("ProductName", "ProductName"),
new System.Data.Common.DataColumnMapping("SupplierID", "SupplierID"),
new System.Data.Common.DataColumnMapping("CategoryID", "CategoryID"),
new System.Data.Common.DataColumnMapping("QuantityPerUnit", "QuantityPerUnit"),
new System.Data.Common.DataColumnMapping("UnitPrice", "UnitPrice"),
new System.Data.Common.DataColumnMapping("UnitsInStock", "UnitsInStock"),
new System.Data.Common.DataColumnMapping("UnitsOnOrder", "UnitsOnOrder"),
new System.Data.Common.DataColumnMapping("ReorderLevel", "ReorderLevel"),
new System.Data.Common.DataColumnMapping("Discontinued", "Discontinued")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("it-IT");
this.dataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd";
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
}
#endregion
private void DataGrid1_SwitchViewMode(object sender, DataGridCommandEventArgs e)
{
Label1.Text = "";
switch (e.CommandName)
{
case "Edit":
DataGrid1.EditItemIndex = e.Item.ItemIndex;
break;
default:
DataGrid1.EditItemIndex = -1;
break;
}
BindGrid();
}
private void DataGrid1_UpdateCommand(object sender, DataGridCommandEventArgs e)
{
CheckBox objCheck = (CheckBox)e.Item.Cells[5].Controls[0];
Label1.Text = "Il nuovo valore per la riga con ID " + DataGrid1.DataKeys[e.Item.ItemIndex].ToString()
+ " è " + objCheck.Checked.ToString();
// visualizza tutte le righe in viewmode
DataGrid1.EditItemIndex = -1;
BindGrid();
}
thank you very much for the quick response.
Bye
|
|
|
|
|
lokolollo wrote:
thank you very much for the quick response.
wow so where you I was re-editing my response
I added the following
or do the Add ing earlier
I do mine in the OnInit handler just after calling InitializeComponent
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
 excuse me for the last post... I was paste too code, for wrong.
Can you repeat your tip,by posting the code ?
here is my actual code:
<br />
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
CheckBoxColumn checkCol = new CheckBoxColumn();<br />
checkCol.HeaderText = "Boolean Field (Editable)";<br />
checkCol.DataField = "Discontinued";<br />
DataGrid1.Columns.Add(checkCol);<br />
<br />
if (!Page.IsPostBack)<br />
{<br />
BindGrid();<br />
}<br />
}<br />
<br />
<br />
private void BindGrid()<br />
{<br />
sqlDataAdapter1.Fill(dataSet11);<br />
DataGrid1.DataBind();<br />
}<br />
<br />
override protected void OnInit(EventArgs e)<br />
{<br />
InitializeComponent();<br />
base.OnInit(e);<br />
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_SwitchViewMode);<br />
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_SwitchViewMode);<br />
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);<br />
}<br />
<br />
private void DataGrid1_SwitchViewMode(object sender, DataGridCommandEventArgs e)<br />
{<br />
Label1.Text = "";<br />
<br />
switch (e.CommandName)<br />
{<br />
case "Edit":<br />
DataGrid1.EditItemIndex = e.Item.ItemIndex;<br />
break;<br />
default:<br />
DataGrid1.EditItemIndex = -1;<br />
break;<br />
}<br />
<br />
BindGrid();<br />
}<br />
<br />
private void DataGrid1_UpdateCommand(object sender, DataGridCommandEventArgs e)<br />
{<br />
CheckBox objCheck = (CheckBox)e.Item.Cells[5].Controls[0];<br />
Label1.Text = "Il nuovo valore per la riga con ID " + DataGrid1.DataKeys[e.Item.ItemIndex].ToString()<br />
+ " è " + objCheck.Checked.ToString();<br />
<br />
DataGrid1.EditItemIndex = -1;<br />
BindGrid();<br />
}<br />
It's being not working.
Thanks.
P.S. Excuse my bad english. I'm Italian 
|
|
|
|
|
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
BindGrid();
}
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
CheckBoxColumn checkCol = new CheckBoxColumn();
checkCol.HeaderText = "Boolean Field (Editable)";
checkCol.DataField = "Discontinued";
DataGrid1.Columns.Add(checkCol);
base.OnInit(e);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_SwitchViewMode);
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_SwitchViewMode);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
}
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
ok, thanks...now it's working.
But, why this?
Page_Load it's executed at every postback, too. Why I have to put that code in the OnInit ?
And...there is a way to implement the inline coding... like this:
<asp:DataGrid id=DataGrid1>
<Columns>
<asp:BoundColumn DataField="ProductID" SortExpression="ProductID" HeaderText="ProductID"></asp:BoundColumn>
<acme:CheckBoxColumn DataField="IsDiscounted" AutoPostBack="true" HeaderText="ProductID"></acme:CheckBoxColumn >
</Columns>
</asp:DataGrid>
Bye
|
|
|
|
|
yup you can do it like that as well
why in the OnInit and before PageLoad - well after the OnInit the viewstate is applied so you need the controls there beforehand to receive the data
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
Shaun or lokolollo,
I am new to asp.net and to adding class lib to my projects. I created the ref and build the two files. I want the easy way to add the following code to my page:
<asp:DataGrid id=DataGrid1>
<Columns>
<asp:BoundColumn DataField="roductID" SortExpression="roductID"
HeaderText="roductID">
</asp:BoundColumn>
<acme:CheckBoxColumn DataField="IsDiscounted" AutoPostBack="true"
HeaderText="roductID">
</acme:CheckBoxColumn >
</Columns>
</asp:DataGrid>
How do I make it so <acme:CheckBoxColumn... /> will work in my aspx page?
|
|
|
|
|