|
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?
|
|
|
|
|
you may have to make the fields in the checkboxcolumn bindable using an attribute [Bindable(true)]
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
|
|
|
|
|
Shaun - not sure if you are still around picking these up but you must have the patience of a saint!! I've been hacking away for a full day trying to make the checks in the boxes persistent and it was this post above that proved to be the one!!
Your willingness to answer all these queries is what makes CP the place it is. You get my 5.
Regards
Angel.
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
How can I use this code to to add a checkbox column without having it bound to a field in the database? I already know a way through the .aspx file, but I would like to do this in the code-behind.
Thanks...
|
|
|
|
|
don't have the DataBind() method do anything or get it to read the data from an alternate source
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
Most of these similar problems are implemented in the ASP.NET(WebForm) but I'm tyring to execute in the WinForm.
So What am I do to do?
If anyone have any information for that, please give me a advise where is the right a way!;)
|
|
|
|
|
I don't work in WinForms as much as I'd like so I can't help you at the moment however there should be some info in this article that would help
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
I have a VB project and need this functionality in VB .
|
|
|
|
|
no you don't
just compile it in its own dll and then use it in your VB app
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
I have coded a VB.Net Version.
I'll upload the Article this Evening.
Greetz cue
|
|
|
|
|
Here now the VB Version, sorry for the Delay:
http://www.codeproject.com/useritems/DataGrid_CheckBox.asp
Greetz cue
|
|
|
|
|
string data = ((DataRowView) container.DataItem)[dataField].ToString();
Type type = ((DataRowView)
container.DataItem).DataView.Table.Columns[dataField].DataType;
Error to o cast (DataRowView)
Specified cast is not valid
What please?
|
|
|
|
|
I'm sorry but I don't understand the question?
Under what conditions do you get the error?
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
The error occurs !
SqlDataReader dr;
...
dataGrid1.DataSource = dr;
dataGrid1.DataBind();
DataBind event CheckBoxColumn...
Error Display!!!
|
|
|
|
|
ahh - I've never tried it with a SqlDataReader only DataSet s
However a quick look in the debugger shows that for SqlDataReader you have a DbDataRecord where I was expecting a DataRowView
so the code could look like this
private void BindData(object sender, EventArgs e)
{
CheckBox box = (CheckBox) sender;
DataGridItem container = (DataGridItem) box.NamingContainer;
box.Checked = false;
box.Enabled = (readOnly == true) ? false:true;
string data="";
Type t = null;
if (container.DataItem is DataRowView)
{
DataRowView vw = (DataRowView) container.DataItem;
data = vw[dataField].ToString();
t = vw.DataView.Table.Columns[dataField].DataType;
}
else if (container.DataItem is DbDataRecord)
{
DbDataRecord rec = (DbDataRecord) container.DataItem;
data = rec[dataField].ToString();
t = rec.GetFieldType(rec.GetOrdinal(dataField));
}
if ((data.Length>0)&&(t!=null))
{
switch (t.ToString())
{
case "System.Boolean":
if (( data == "True") || (data == "true"))
{
box.Checked = true;
}
break;
default:
break;
}
}
}
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
Thanks ! Congratulations !
you are the best developer to .NET.
Very The Best!!!!!
|
|
|
|
|
I have a little twist on the whole checkbox column in the datagrid situation which maybe you can help.
I am currently writing a software library checkout system as an exercise. For each item in the list, if its available to be checked out there is a checkbox for the user to check, else I replace the checkbox with words "checked-out". To do this, I have a column of checkboxes created by using the TemplateColumn, during the ItemDataBound event I modify the column. In the footer for that column I have a button, so that the user can request all the items that are currently checked. I am having trouble getting the proper messages to figure out what the user has checked. Basically I wanna know how to update the column of checkboxes at once, versus going row by row, like the functionality you see in your standard web email programs "delete all checked".
Thanks for any help.
|
|
|
|
|
Hi
I had a quick play (1/2hr is all you get for free ) and this is what I came up with.
Using my class as above I created my template column like this
CheckBoxColumn checkCol3 = new CheckBoxColumn(true);
checkCol3.AutoPostBack = false;
checkCol3.HeaderText = "Boolean Field (Postpone Editable)";
checkCol3.DataField = "Boolean";
...
DataGrid3.Columns.Add(checkCol3);
As you can see I didn't add a handler for the callback event - it only seemed to get called once anyway (something I'll look into later).
Then in my handler for the button click I extracted the checkbox ids directly from the Request object ie
private void Button1_Click(object sender, System.EventArgs e)
{
string x=Request.Form.Get("DataGrid3:_ctl2:_ctl0");
x=Request.Form.Get("DataGrid3:_ctl3:_ctl0");
}
I worked out the IDs from the HTML returned to my browser but I you should be able to do it programmatically.
[ID of grid]:_ctl[row number + 1 (as header is first row)]:_ctl[index of control in row]
If the above code returned null then it was unchecked else it returned a string with 'on'.
HTH
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
Hi I found the article is pretty nice for my current project. However, I'd like to know how can I retrieve the checkbox event when the checkbox has been checked?
I'm thinking to do "addhandler chk.CheckedChanged, addressOf MyEvent" (sorry i'm using VB.net) within the template column. This event triggered automatically within the checkbox template column but how can this info to be passed out to datagrid object??
Thanks in advance!!
|
|
|
|
|