Click here to Skip to main content
15,902,635 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionhow to store first page's primary key key value in second pages foreign key attribute. Pin
jattscorpion17-Feb-10 7:24
jattscorpion17-Feb-10 7:24 
AnswerRe: how to store first page's primary key key value in second pages foreign key attribute. Pin
Abhishek Sur17-Feb-10 9:48
professionalAbhishek Sur17-Feb-10 9:48 
GeneralRe: how to store first page's primary key key value in second pages foreign key attribute. Pin
jattscorpion17-Feb-10 12:31
jattscorpion17-Feb-10 12:31 
QuestionHow to set the sender address (Field From) usin MAPI Pin
nahelpa17-Feb-10 6:41
nahelpa17-Feb-10 6:41 
QuestionEvent on asp:calendar Pin
_ASPAle_17-Feb-10 6:06
_ASPAle_17-Feb-10 6:06 
AnswerRe: Event on asp:calendar Pin
Brij17-Feb-10 19:22
mentorBrij17-Feb-10 19:22 
GeneralRe: Event on asp:calendar Pin
_ASPAle_18-Feb-10 0:04
_ASPAle_18-Feb-10 0:04 
QuestionNeed some assistance with adding a datarow to a datatable Pin
Will Talley17-Feb-10 5:34
Will Talley17-Feb-10 5:34 
I'm working on a database-driven food pantry application which will allow a user to add a new household to the database. The user would theoretically add members to this household by using a modal popup form to add a new family member by either entering new information in a form, or search for a person who is already in the system but is not assigned to a household. The new family member would be added to a datable which is then databinded to a gridview. When the household information is saved, we theoretically add everyone in the datable to the newly created household by changing their HHID (the foreign key in the database linking them to the database) to that of the newly created household. It makes use of Ajax update panels to dynamically add data without reloading the page.

Now here is where the problem comes into play: when the user adds the new family member (either by searching or entering new data), the datatable is cleaned out, and only the newly created family member shows up. My code is as follows:

This function is what actually puts the data into the datatable.

protected void AddNewFamilyMemberToDatatable(string SSN, string First, string Last, string DOB, string AdultChild, string Gender, bool Head, String ConsentForm, string Ethnicity)
{
    FamilyWarning.Text += "<br/>There are now" + NewHouseholdDatatable.Rows.Count.ToString() + " rows in the table before adding empty columns and after getting changes";
    AddEmptyColumnsToDatatable(NewHouseholdDatatable);//This is used to add empty columns to the datatable in case they aren't there already, otherwise I'd get a "does not contain column _ exception.

     FamilyWarning.Text += "<br/>There are now" + NewHouseholdDatatable.Rows.Count.ToString() + " rows in the table after adding empty columsn";

    FamilyWarning.Text += "<br/>There are now" + NewHouseholdDatatable.Rows.Count.ToString() + " rows in the table after assigning datasource";

    //NewHouseholdDatable is the name of the datatable I'm using, and it's set up in the page's Init event.
    DataRow Row = NewHouseholdDatatable.NewRow();
    //This stuff simply sets the values to the new row
    if (Head)
    {
        Row["HeadOfHousehold"] = true;
    }
    else
    {
        Row["HeadOfHousehold"] = false;

    }
    Row["Firstname"] = First;
    Row["DOB"] = DOB;
    Row["Lastname"] = Last;
    Row["SSN"] = SSN;
    Row["AdultChild"] = AdultChild;
    Row["MaleFemale"] = Gender;

    if (ConsentForm == "1")
    { Row["ConsentForm"] = true; }
    else
    { Row["ConsentForm"] = false; }
    Row["Ethnicity"] = Ethnicity;
    if (!CheckIsDate(DOB))
    {
        Row["Age"] = 0;
        Row["DateOfBirth"] = "Unknown, please edit and enter proper data";
    }
    else
    {
        Row["Age"] = GetAge(DateTime.Parse(DOB));
        DateTime DateAndTimeOfBirth = Convert.ToDateTime(DOB);
        Row["DateOfBirth"] = DateAndTimeOfBirth.ToShortDateString();
    }
    try
    {
        FamilyWarning.Text += "<br/>There are " + NewHouseholdDatatable.Rows.Count.ToString() + " rows in the table before adding";
            NewHouseholdDatatable.Rows.Add(Row);


        FamilyWarning.Text += "<br/>There are now" + NewHouseholdDatatable.Rows.Count.ToString() + " rows in the table after accepting changes";
        ClearForm();
        //FamilyMembers is the name of the gridview that I'm binding it to.,
     FamilyMembers.DataSource = NewHouseholdDatatable;
        FamilyMembers.DataBind();
        FamilyWarning.Text += "<br/>There are now" + NewHouseholdDatatable.Rows.Count.ToString() + " rows in the table after databinding";
       // FamilyWarning.Text = Row["Firstname"] + " " + Row["Lastname"] + " successfully added.  There are " + NewHouseholdDatatable.Rows.Count.ToString() + " rows in the table.";

    }
    catch (Exception ex)
    {
        FamilyWarning.Text += "<br/>Unable to add this person to the table, " + ex.Message;
    }

}

AnswerRe: Need some assistance with adding a datarow to a datatable Pin
Abhishek Sur17-Feb-10 5:59
professionalAbhishek Sur17-Feb-10 5:59 
GeneralRe: Need some assistance with adding a datarow to a datatable Pin
Will Talley18-Feb-10 2:38
Will Talley18-Feb-10 2:38 
AnswerRe: Need some assistance with adding a datarow to a datatable Solved! Pin
Will Talley18-Feb-10 4:58
Will Talley18-Feb-10 4:58 
Questionbinding data to a data list Pin
arindam201017-Feb-10 5:18
arindam201017-Feb-10 5:18 
AnswerRe: binding data to a data list Pin
Abhishek Sur17-Feb-10 6:02
professionalAbhishek Sur17-Feb-10 6:02 
GeneralRe: binding data to a data list Pin
arindam201017-Feb-10 6:56
arindam201017-Feb-10 6:56 
GeneralRe: binding data to a data list Pin
Abhishek Sur17-Feb-10 9:44
professionalAbhishek Sur17-Feb-10 9:44 
AnswerRe: binding data to a data list Pin
Anurag Gandhi17-Feb-10 6:37
professionalAnurag Gandhi17-Feb-10 6:37 
GeneralRe: binding data to a data list Pin
arindam201017-Feb-10 6:54
arindam201017-Feb-10 6:54 
GeneralRe: binding data to a data list Pin
Anurag Gandhi17-Feb-10 15:52
professionalAnurag Gandhi17-Feb-10 15:52 
QuestionWeb Service Protection with Client Certificates Pin
captainone17-Feb-10 3:55
captainone17-Feb-10 3:55 
AnswerRe: Web Service Protection with Client Certificates Pin
Ennis Ray Lynch, Jr.17-Feb-10 5:19
Ennis Ray Lynch, Jr.17-Feb-10 5:19 
GeneralRe: Web Service Protection with Client Certificates Pin
captainone18-Feb-10 17:46
captainone18-Feb-10 17:46 
GeneralRe: Web Service Protection with Client Certificates Pin
captainone18-Feb-10 18:19
captainone18-Feb-10 18:19 
GeneralRe: Web Service Protection with Client Certificates Pin
Ennis Ray Lynch, Jr.19-Feb-10 4:51
Ennis Ray Lynch, Jr.19-Feb-10 4:51 
GeneralRe: Web Service Protection with Client Certificates Pin
captainone19-Feb-10 7:06
captainone19-Feb-10 7:06 
QuestionGridView Image button Pin
Abbas_here17-Feb-10 3:55
Abbas_here17-Feb-10 3:55 

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.