Click here to Skip to main content
15,886,799 members
Home / Discussions / C#
   

C#

 
AnswerRe: forcing users to use English language Pin
Manfred Rudolf Bihy13-Feb-13 22:29
professionalManfred Rudolf Bihy13-Feb-13 22:29 
AnswerRe: forcing users to use English language Pin
N a v a n e e t h13-Feb-13 22:30
N a v a n e e t h13-Feb-13 22:30 
GeneralRe: forcing users to use English language Pin
harold aptroot13-Feb-13 23:33
harold aptroot13-Feb-13 23:33 
AnswerRe: forcing users to use English language Pin
ali_heidari_14-Feb-13 5:55
ali_heidari_14-Feb-13 5:55 
AnswerRe: forcing users to use English language Pin
jschell14-Feb-13 11:46
jschell14-Feb-13 11:46 
Questionwebbrowser control in c# Pin
eldhose198513-Feb-13 18:28
eldhose198513-Feb-13 18:28 
AnswerRe: webbrowser control in c# Pin
N a v a n e e t h13-Feb-13 19:07
N a v a n e e t h13-Feb-13 19:07 
QuestionGridView FindControl LINQ Update Pin
RickSharp13-Feb-13 12:34
RickSharp13-Feb-13 12:34 
Hey Guys,
I know I can access my ItemTemplated Checkbox this way:
C#
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:
C#
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:
ASP.NET
<asp:GridView ID="GridView1" runat="server"
                AutoGenerateColumns="False"
                GridLines="Both"
                CssClass="mGrid">
                <Columns>
                    <asp:TemplateField HeaderText="Select">                     
                        <HeaderTemplate>
                            <asp:CheckBox ID="chkBxHeader" runat="server" />
                        </HeaderTemplate>
                         <ItemTemplate>
                            <asp:CheckBox ID="chkBxSelect" runat="server"/>
                        </ItemTemplate>
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                    </asp:TemplateField>
                </Columns></asp:GridView>


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:
C#
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;
                
                if(ckBxSelect.Checked)
                {
                newRecord.Status = "True";  
                }
                Else 
                {
                 newRecord.Status = "False";
                }        
                newRecord.DateTimeSubmitted = DateTime.Now;
 
                dbc.mySQLTableName.InsertOnSubmit(newRecord);
 
            }
 
            dbc.SubmitChanges();
}



However,
This code will throw an exception because of the object not being set to a reference.

Please help. Is there a better way do update my database?
Im totally lost. Frown | :(
AnswerRe: GridView FindControl LINQ Update Pin
RickSharp13-Feb-13 12:43
RickSharp13-Feb-13 12:43 
AnswerRe: GridView FindControl LINQ Update Pin
Richard MacCutchan13-Feb-13 22:29
mveRichard MacCutchan13-Feb-13 22:29 
GeneralRe: GridView FindControl LINQ Update Pin
RickSharp14-Feb-13 6:43
RickSharp14-Feb-13 6:43 
GeneralRe: GridView FindControl LINQ Update Pin
Richard MacCutchan14-Feb-13 6:58
mveRichard MacCutchan14-Feb-13 6:58 
GeneralRe: GridView FindControl LINQ Update Pin
RickSharp14-Feb-13 10:31
RickSharp14-Feb-13 10:31 
GeneralRe: GridView FindControl LINQ Update Pin
RickSharp14-Feb-13 13:28
RickSharp14-Feb-13 13:28 
QuestionC# Cannot access a disposed object Pin
classy_dog13-Feb-13 8:06
classy_dog13-Feb-13 8:06 
AnswerRe: C# Cannot access a disposed object Pin
Pete O'Hanlon13-Feb-13 8:13
mvePete O'Hanlon13-Feb-13 8:13 
AnswerRe: C# Cannot access a disposed object Pin
jschell13-Feb-13 10:15
jschell13-Feb-13 10:15 
QuestionIDisposable spread Pin
Orjan Westin13-Feb-13 2:45
professionalOrjan Westin13-Feb-13 2:45 
AnswerRe: IDisposable spread Pin
DaveyM6913-Feb-13 4:52
professionalDaveyM6913-Feb-13 4:52 
AnswerRe: IDisposable spread Pin
Keith Barrow13-Feb-13 5:13
professionalKeith Barrow13-Feb-13 5:13 
GeneralRe: IDisposable spread Pin
PIEBALDconsult13-Feb-13 17:46
mvePIEBALDconsult13-Feb-13 17:46 
GeneralRe: IDisposable spread Pin
N a v a n e e t h13-Feb-13 18:59
N a v a n e e t h13-Feb-13 18:59 
GeneralRe: IDisposable spread Pin
Orjan Westin13-Feb-13 22:33
professionalOrjan Westin13-Feb-13 22:33 
AnswerRe: IDisposable spread Pin
N a v a n e e t h13-Feb-13 18:56
N a v a n e e t h13-Feb-13 18:56 
AnswerRe: IDisposable spread Pin
BobJanova13-Feb-13 23:54
BobJanova13-Feb-13 23:54 

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.