Forms Data Controls :: Changing In Gridview With Checkbox
Aug 14, 2010
First off, sorry if this is in the wrong section. I have a gridview that loads from a SQL database. It has three columns, the first being a template column with a checkbox, the second being a name from the database, and the third being a field from the database related to that name. (the third column is empty). I want to be able to click on the check box in each row, and automatically have the third column populate with data that the user can select from a drop down list at the top of the screen or something. I am using VB, and I basically just need a way to make this checkbox, add a value from somewhere into the database. (Also, I know that I can just use Edit in the gridview to change data, but there will be a long list, and that way gets quite time consuming) I hope this makes sense, if not I can try rewording it.
I am trying to edit data using checkbox value. Firstly, I created popup window which using querystring some data from main page. In popup window, I want to change the checkbox value. For example, I made setSpare column and given the value to show bit data type such as 0 or 1 using checkbox(false or true). If some data has non setSpare(means 0), it wil lbe come out uncheckbox. If I want to check it and clicking submit button, It was not change. I am going to show the code below.
public partial class AddSpare : BasePage { string ObjectId; protected void Page_Load(object sender, EventArgs e) { ObjectId = Request.QueryString["ObjectId"]; displayComInfo(ObjectId); } protected void displayComInfo(string ObjectId) // it informed relative data on web through using DB. { string query = "usp_ShowComputerList"; try { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SCSConnectionString2"].ConnectionString)) { SqlCommand cmd = new SqlCommand(query, conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter paramobjectId = cmd.Parameters.Add("@ObjectId", System.Data.SqlDbType.Int); paramobjectId.Value = ObjectId; conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { ModelTxt.Text = dr["Model"].ToString(); ModelTxt.ReadOnly = true; ComputerTxt.Text = dr["ComputerName"].ToString(); ComputerTxt.ReadOnly = true; userTxt.Text = dr["UserName"].ToString(); userTxt.ReadOnly = true; ntTxt.Text = dr["NtLogon"].ToString(); ntTxt.ReadOnly = true; HDDTxt.Text = dr["HddSize"].ToString() + "GB"; HDDTxt.ReadOnly = true; RAMTxt.Text = dr["MemorySize"].ToString() + "GB"; RAMTxt.ReadOnly = true; SerialNoTxt.Text = dr["SerialNo"].ToString(); SerialNoTxt.ReadOnly = true; TextBox1.Text = dr["Spare"].ToString(); inputChkSpare.Checked = (bool)dr["Spare"]; //(bool)dr["Spare"] display false or true. dr.Close(); } } } catch (Exception ex) { MessagePanel1.Type = MessageType.Error; MessagePanel1.Text = MessagePanel1.Text = "This is an error." + ex.Message; } } protected void okBtn_Click(object sender, EventArgs e) { string query = "usp_SetSpare"; try { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SCSConnectionString2"].ConnectionString)) { SqlCommand cmd = new SqlCommand(query, conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter paramobjectId = cmd.Parameters.Add("@objId", System.Data.SqlDbType.Int); SqlParameter paramspare = cmd.Parameters.Add("@spare", System.Data.SqlDbType.Char); paramobjectId.Value = ObjectId; if (inputChkSpare.Checked == true) // if I change the check box, it does not bring the changed value. It will bring the above value(already displayed thing) { paramspare.Value = "1"; } else { paramspare.Value = "0"; } conn.Open(); cmd.ExecuteNonQuery(); cancelBtn.Value = "Close"; okBtn.Enabled = false; MessagePanel1.Type = MessageType.Information; MessagePanel1.Text = "This computer is spare from now."; } } catch (Exception ex) { MessagePanel1.Type = MessageType.Error; MessagePanel1.Text = MessagePanel1.Text = "This is an error." + ex.Message; } }
I've got a details view control on a page. One of the columns, from the database table, is a bit field. It is not nullable, and that's the way it has to be. Also, in most cases, when inserting data, it will be true (1) be default. I've found in testing, when inserting data, that it was false, for some reason. So, I changed the column to a template field and went to the InsertItemTemplate for that column, and changed the checkbox Checked property to True, instead of the default False. However, it has really screwed up the page because now it won't save anything at all! When I try saving something using the details view, it does show the checkbox as being checked, but man, once I try saving it I get an error message back from the database saying that the column doesn't allow for nulls.
Huh??? How in heck can the column on the page have a value (it is checked), but when it goes to save something it fails? Furthermore, before I converted this field to a template field, it worked perfectly. I tested several other insertions, and they all worked. But when I converted it to a template field, it stopped working? What's that about? I even tried setting the default value for the Checked property of the checkbox back to False, but that still doesn't work, it still wants to pass in a null. What's going on here? Why is it that converting a field to a template field, which was working perfectly fine before I made the convension, stop it from working at all?
I have a repeater control on my page. Here's my code:
[Code]....
I would like to change a background color of the item's <div> when user checks the chechbox. I have an event handler for CheckedChange event but I don't know how can I get access to this div from the event handler.
I want to select all checkBox in Gridview when click to header checkBox.I have created design such that CheckBox is not available to header of Gridview.It is in other table. Below is design of gridview.
I have a GridView that I was previously populating via an ObjectDataSource, and this code was working perfectly (ie, when the checkbox was checked Checkbox.Checked = true):
I have a question, I have a gridview that shows a red balloon as imagebutton in one of the cells. Now i want to be able to let a users press the button, write a value in a record in the database and then change the red balloon to a yellow one. When the user wants (at any given time) wants the undo the value again the record should be rewriten again and the yellow ballon should be red again. Any tip is more than welcome :)
I have a gridview bound to a SQL Select statement. I want the binding of one of the columns to depend on one of the values in the database record. For example, say I have a SQL table containing FirstName, LastName, ShowFirstName.
I want a the Name column in my Gridview to be bound to FirstName if ShowFirstName is 1, and bound to LastName if ShowFirst Name is 0.
I have made a gridview by assigning a sqldatareader object to it to display records....but i want to change the headertext of each column.i dont want the default name stored in the database how do i change the headertext?
I would like to change color of the gridView depending on the value from table that is bounded to the grid. I actually don't show this value on the grid. I tried by using additional field with visible=false, but the cell is string empty in this way. I don't know how to solve this in some other way?
I used this code, but as I said the value is empty:
[Code]....
Is it possible to solve this by getting value directly from bounded table and not from rows cell?
When I try to change a page on my gridview, I keep getting this error: Index was out of range. Must be non-negative and less than the size of the collection. How can I fix this? The line the error highlights is the one below:
I have a gridview where I have TemplateField and I have bind with Coulmn Name. In Run time I would like to change the coulmn name but I am getting error.
Nw i want to change the TempPwd checkboxfield from another aspx file namely NewUserLogin.aspx, So is it possible? The idea behind doing this is, as soon as the user enters a new password in the NewUserLogin.aspx page, the checkboxfield in the GridView of CustomerSetup.aspx file should be unset.
I'm attempting to bind multiple datasources to a single Gridview. Can someone direct me on how to change the below <%# Bind("") %> programatically in the code behind. For example, change "HRID" to "PayrollID" to account for a different column. the dataSource binds to the Gridview so the Rows will not be created yet.
I know how to accomplish this with a boundField, but I'm having issues with setting the text of the label in the ItemTemplate.
This is an ASP.NET 3.5 project being created with VS2008. One page contains a gridview with six columns. One of the columns displays standard, 17 character , Vehicle Identification Numbers (VIN). The VIN numbers display normally when the page is rendered. However, when the gridview is exported to Excel, the VIN numbers change. For example, in the gridview, the VIN might be 12345678912345678But when the gridview exports into Excel, that same VIN becomes 1.23457E+16The value of that Excel cell changes to 12345678912345600, changing the last two digits from 78 to 00. It does this for every VIN in the gridview table.I did some Googling but couldn't find anything specifically on this issue. Has anyone seen it before? Is there a way to format the column in the gridview so that Excel will accept it as literal text? I tried programmatically adding a style called 'text' to that column but that had no effect on the outcome. All of the other columns are behaving normally.
im building a simple message messenger web application, i currently have a column in my database dedicated to the status of a message. Its bound to the third column in a datagrid.
After converting the column to a TemplateField and using a Label to fetch the data how do i change the text from the database to a small message, e.g. if the data in the database (as an interger) is 0. how do i change the interger to a string to display "UnRead". Do i need to do this during the databinding call or after the grid has been databound?
I know it would be easier to use a boolean and checkbox control but the interger column represents more values than true or false.
I have a gridview which i have enabled paging. When i select a page in the footer, the page postbacks, and I lose all data.I am lost on how to enable paging and maintain the data in the table.I manually insertthe information into a datatable then bind because of the way i have to get the information.Here is what I have so far: [Code]...