GridView FindControl LINQ Update
-
Hey Guys, I know I can access my ItemTemplated Checkbox this way:
foreach (GridViewRow rowItem in GridView1.Rows)
{CheckBox ckBxSelect = ((CheckBox)rowItem.FindControl("chkBxSelect")); // chk.checked will access the checkbox state on button click event if (ckBxSelect.Checked) { Response.Write("True"); }
}
Ive built 1 LINQ object joined from 2 Datatables which comes from 2 WebServices. My GridView is bound to my LINQ object. When the user clicks submit, a foreach loop inserts that LINQ object into my database like so:
protected void Button1_Click(object sender, EventArgs e)
{
mySQLDatabaseDataContext dbc = new mySQLDatabaseDataContext("Data Source=JBBBZ7V1\\SQLEXPRESS;Initial Catalog=WLSData;Integrated Security=True");mySQLTableName newRecord; foreach (var item in LINQobject) { newRecord = new mySQLTableName(); newRecord.CustName = forAppr.custName; newRecord.Status = ""; newRecord.DateTimeSubmitted = DateTime.Now; dbc.mySQLTableName.InsertOnSubmit(newRecord); } dbc.SubmitChanges();
}
Like I said, my checkbox is in a TemplateField like so:
<HeaderTemplate> </HeaderTemplate> <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
When I am inserting from my LINQ object, I would like the "Status" field to update with "True" if checkbox is checked or "False" if checkbox is not checked. Like so:
protected void Button1_Click(object sender, EventArgs e)
{
mySQLDatabaseDataC -
Hey Guys, I know I can access my ItemTemplated Checkbox this way:
foreach (GridViewRow rowItem in GridView1.Rows)
{CheckBox ckBxSelect = ((CheckBox)rowItem.FindControl("chkBxSelect")); // chk.checked will access the checkbox state on button click event if (ckBxSelect.Checked) { Response.Write("True"); }
}
Ive built 1 LINQ object joined from 2 Datatables which comes from 2 WebServices. My GridView is bound to my LINQ object. When the user clicks submit, a foreach loop inserts that LINQ object into my database like so:
protected void Button1_Click(object sender, EventArgs e)
{
mySQLDatabaseDataContext dbc = new mySQLDatabaseDataContext("Data Source=JBBBZ7V1\\SQLEXPRESS;Initial Catalog=WLSData;Integrated Security=True");mySQLTableName newRecord; foreach (var item in LINQobject) { newRecord = new mySQLTableName(); newRecord.CustName = forAppr.custName; newRecord.Status = ""; newRecord.DateTimeSubmitted = DateTime.Now; dbc.mySQLTableName.InsertOnSubmit(newRecord); } dbc.SubmitChanges();
}
Like I said, my checkbox is in a TemplateField like so:
<HeaderTemplate> </HeaderTemplate> <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
When I am inserting from my LINQ object, I would like the "Status" field to update with "True" if checkbox is checked or "False" if checkbox is not checked. Like so:
protected void Button1_Click(object sender, EventArgs e)
{
mySQLDatabaseDataC -
Hey Guys, I know I can access my ItemTemplated Checkbox this way:
foreach (GridViewRow rowItem in GridView1.Rows)
{CheckBox ckBxSelect = ((CheckBox)rowItem.FindControl("chkBxSelect")); // chk.checked will access the checkbox state on button click event if (ckBxSelect.Checked) { Response.Write("True"); }
}
Ive built 1 LINQ object joined from 2 Datatables which comes from 2 WebServices. My GridView is bound to my LINQ object. When the user clicks submit, a foreach loop inserts that LINQ object into my database like so:
protected void Button1_Click(object sender, EventArgs e)
{
mySQLDatabaseDataContext dbc = new mySQLDatabaseDataContext("Data Source=JBBBZ7V1\\SQLEXPRESS;Initial Catalog=WLSData;Integrated Security=True");mySQLTableName newRecord; foreach (var item in LINQobject) { newRecord = new mySQLTableName(); newRecord.CustName = forAppr.custName; newRecord.Status = ""; newRecord.DateTimeSubmitted = DateTime.Now; dbc.mySQLTableName.InsertOnSubmit(newRecord); } dbc.SubmitChanges();
}
Like I said, my checkbox is in a TemplateField like so:
<HeaderTemplate> </HeaderTemplate> <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
When I am inserting from my LINQ object, I would like the "Status" field to update with "True" if checkbox is checked or "False" if checkbox is not checked. Like so:
protected void Button1_Click(object sender, EventArgs e)
{
mySQLDatabaseDataC -
RickSharp wrote:
This code will throw an exception because of the object not being set to a reference.
Then you need to fix that bug. Glancing at your code it seems you are using the variable
ckBxSelect
without setting it to refer to any object. -
The only way I know how to refer to a checkbox in a TemplateField is by using GridViewRow in a foreach loop. If there is another way to find that control then i would love to know.
-
I don't know what relevance this has to do with my comment. If you do not understand the error "object not being set to a reference", then I would suggest rereading your C# documentation on objects and references.
-
Thanks for the insight. I'll go reread my C# manual... So i read it, and I guess I'm too stupid to understand it. Maybe someone else can help.
I have resolved this issue by reading an asp lablel key into a dictionary. then if the dictionary had that label insert into my database. Sorry if I was vague but I'm very new to all of this so I mostly i just make others made by asking inane questions that are apparently to unclear to understand. :(