Click here to Skip to main content
15,867,568 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionwebsite Pin
Member 1247519331-Jan-19 2:29
Member 1247519331-Jan-19 2:29 
AnswerRe: website Pin
F-ES Sitecore1-Feb-19 5:46
professionalF-ES Sitecore1-Feb-19 5:46 
QuestionAngularJS package.json file to AngularCLI project Pin
simpledeveloper24-Jan-19 10:24
simpledeveloper24-Jan-19 10:24 
AnswerRe: AngularJS package.json file to AngularCLI project Pin
Richard MacCutchan24-Jan-19 22:15
mveRichard MacCutchan24-Jan-19 22:15 
GeneralRe: AngularJS package.json file to AngularCLI project Pin
simpledeveloper25-Jan-19 11:59
simpledeveloper25-Jan-19 11:59 
GeneralRe: AngularJS package.json file to AngularCLI project Pin
Bohdan Stupak26-Jan-19 4:37
professionalBohdan Stupak26-Jan-19 4:37 
GeneralRe: AngularJS package.json file to AngularCLI project Pin
simpledeveloper28-Jan-19 11:12
simpledeveloper28-Jan-19 11:12 
QuestionHow do I determine rowindex for table rows? Pin
samflex21-Jan-19 15:25
samflex21-Jan-19 15:25 
Greetings experts,

I was looking for windows forms but didn't find one. I hope it is ok to post here.

I am trying to display records from the database so I can add/delete/update records.

The way I have this set up, clicking on a row of records populates the textboxes associated with the rows on the code below.

So far, when I click on any row, the textboxes are not getting populated.

My assumption is that I am not getting the correct rowindexes for each of the rows in DataGridView control.

Is there an easier way to find out which rowindex each of the rows belong to.

Better yet, is there a better way of displaying the records and when each row is clicked, the associated textboxes are populated?

The datagridview rows are getting populated. What is not working is clicking on a row and getting textboxes populated.

Your assistance as usual is greatly appreciated.

//Display Data in DataGridView
private void DisplayData()
{
    con.Open();
    DataTable dt=new DataTable();
    adapt=new SqlDataAdapter("SELECT t.TransactionID,m.FullName,convert(varchar,m.registration_date,101) as registration_date," +
             "m.enelope_number,Reg_Fee,t.Amount,t.AmountPaid,t.AmountOwed as Past_Due " +
             "from dbo.Transactions AS t INNER JOIN dbo.Members AS m ON t .MemberID = m.MemberID INNER JOIN " +
             "dbo.PaymentTypes AS p ON t .TypeID = p.PaymentTypeID", con);
    adapt.Fill(dt);
    dataGridView1.DataSource = dt;
    con.Close();
}
//Clear Data
private void ClearData()
{
    Email.Text = "";
    Phone.Text = "";
    TransactionID = 0;
}
//dataGridView1 RowHeaderMouseClick Event
private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
    TransactionID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
    memberName.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
    Email.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
    Phone.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
    Address.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
    member_sex.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
    date_member_registered.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
    envelope_number.Text = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
}
//Update Record
private void btn_Update_Click(object sender, EventArgs e)
{
    if (Email.Text != "" && Phone.Text != "")
    {
        cmd = new SqlCommand("update Transactions set Name=@name,State=@state where transactionID=@id", con);
        con.Open();
        cmd.Parameters.AddWithValue("@id", TransactionID);
        cmd.Parameters.AddWithValue("@amount", Email.Text);
        cmd.Parameters.AddWithValue("@paid", Phone.Text);
        cmd.ExecuteNonQuery();
        MessageBox.Show("Record Updated Successfully");
        con.Close();
        DisplayData();
        ClearData();
    }
    else
    {
        MessageBox.Show("Please Select Record to Update");
    }
}
//Delete Record
private void btn_Delete_Click(object sender, EventArgs e)
{
    if(TransactionID!=0)
    {
        cmd = new SqlCommand("delete from Transactions where transactionID=@id",con);
        con.Open();
        cmd.Parameters.AddWithValue("@id",TransactionID);
        cmd.ExecuteNonQuery();
        con.Close();
        MessageBox.Show("Record Deleted Successfully!");
        DisplayData();
        ClearData();
    }
    else
    {
        MessageBox.Show("Please Select Record to Delete");
    }
}


Does anyone
AnswerRe: How do I determine rowindex for table rows? Pin
Richard Deeming22-Jan-19 0:49
mveRichard Deeming22-Jan-19 0:49 
QuestionMessage Removed Pin
21-Jan-19 12:00
simpledeveloper21-Jan-19 12:00 
QuestionThe reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK Pin
simpledeveloper18-Jan-19 12:46
simpledeveloper18-Jan-19 12:46 
AnswerRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
Richard MacCutchan18-Jan-19 22:19
mveRichard MacCutchan18-Jan-19 22:19 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
simpledeveloper23-Jan-19 13:52
simpledeveloper23-Jan-19 13:52 
AnswerRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
Richard Deeming21-Jan-19 0:18
mveRichard Deeming21-Jan-19 0:18 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
simpledeveloper21-Jan-19 19:03
simpledeveloper21-Jan-19 19:03 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
simpledeveloper21-Jan-19 19:03
simpledeveloper21-Jan-19 19:03 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
Nelek21-Jan-19 19:05
protectorNelek21-Jan-19 19:05 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
simpledeveloper22-Jan-19 16:43
simpledeveloper22-Jan-19 16:43 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
Nelek22-Jan-19 21:25
protectorNelek22-Jan-19 21:25 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
simpledeveloper23-Jan-19 9:48
simpledeveloper23-Jan-19 9:48 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
Mycroft Holmes23-Jan-19 10:23
professionalMycroft Holmes23-Jan-19 10:23 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
simpledeveloper23-Jan-19 13:46
simpledeveloper23-Jan-19 13:46 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
Mycroft Holmes23-Jan-19 14:42
professionalMycroft Holmes23-Jan-19 14:42 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
simpledeveloper23-Jan-19 16:55
simpledeveloper23-Jan-19 16:55 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
simpledeveloper23-Jan-19 17:36
simpledeveloper23-Jan-19 17:36 

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.