Greeting all
I have a gridView as photo below
A position dropdownlist connect alone with (SQLDATASOURC) to get Brunch name and Id and implement them to Dropdownlist......Anyway..when I select any item from dropdownlist showing that mistake
as photo beow:

I used many many many solutions to resolve that no way..
Have anyone a perfect way to resolve that mistake..
Take a view a bout code below:
- protected void gvjobsshow_RowUpdating(object sender, GridViewUpdateEventArgs e)
- {
- try
- {
- using (SqlConnection sqlcon = new SqlConnection(connectionString))
- {
- sqlcon.Open();
- string query = "UPDATE Jobs SET Job_title = @Job_title, Job_desc = @Job_desc,P_date = @P_date, C_date = @C_date,Branch_Id = @Branch_Id, JType_Id = @JType_Id, JEnable = @JEnable WHERE (Jobs.Id = @Id)";
- string Pday = ((TextBox)gvjobsshow.Rows[e.RowIndex].FindControl("TB_PDate")).Text;
- string Cday = ((TextBox)gvjobsshow.Rows[e.RowIndex].FindControl("TBCdate_E")).Text;
- //====That solution to get DropDownlist value and imlement it is Variable, and then implement a variable in SQL Upadate=====
- DropDownList DDLBrID1 = (DropDownList)gvjobsshow.Rows[e.RowIndex].FindControl("DDl_Po_E");
- string DDLBrID2 = DDLBrID1.SelectedItem.Value.ToString();
- SqlCommand sqlcmd = new SqlCommand(query, sqlcon);
- sqlcmd.Parameters.AddWithValue("@Job_title", (gvjobsshow.Rows[e.RowIndex].FindControl("TB_Tit_E") as TextBox).Text.Trim());
- sqlcmd.Parameters.AddWithValue("@Job_desc", (gvjobsshow.Rows[e.RowIndex].FindControl("TbDes_E") as TextBox).Text.Trim());
- sqlcmd.Parameters.AddWithValue("@P_date", Pday);
- sqlcmd.Parameters.AddWithValue("@C_date", Cday);
- sqlcmd.Parameters.AddWithValue("@Branch_Id", DDLBrID2);
- //sqlcmd.Parameters.Add("@Branch_Id", SqlDbType.Int).Value = ((DropDownList)gvjobsshow.Rows[e.RowIndex].FindControl("DDl_Po_E"));
- //==== I used that solution to access to dropdownlist value and return it with [[Convert.ToInt32]] but no way...
- //sqlcmd.Parameters.AddWithValue("@Branch_Id", Convert.ToInt32((gvjobsshow.Rows[e.RowIndex].FindControl("DDl_Po_E"))));
- sqlcmd.Parameters.AddWithValue("@JType_Id", Convert.ToInt32((gvjobsshow.Rows[e.RowIndex].FindControl("DDl_Miss_E"))));
- sqlcmd.Parameters.AddWithValue("@JEnable", Convert.ToBoolean((gvjobsshow.Rows[e.RowIndex].FindControl("Ch_E") as CheckBox).Checked));
- sqlcmd.Parameters.AddWithValue("@Id", Convert.ToInt32(gvjobsshow.DataKeys[e.RowIndex].Value.ToString()));
- sqlcmd.ExecuteNonQuery();
- gvjobsshow.EditIndex = -1;
- GVShowJobs();
- JobSuUp.Text = "Selected Record has been Updated.";
- }
- }
- catch (Exception ex)
- {
- JobFaUp.Text = ex.Message;
- }
- }

Aktham MahmoudPosted Jan 31, 2020, 1:55 AM
Ramachandran MPosted Jan 31, 2020, 12:07 AM
Aktham MahmoudPosted Jan 30, 2020, 5:35 PM
Ramachandran MPosted Jan 30, 2020, 8:06 AM
DDLBrID2 value in quick window . if value is not null then found which property has value in quick window after that change the code as runnable.
Aktham MahmoudPosted Jan 30, 2020, 7:18 AM
Ramachandran MPosted Jan 30, 2020, 12:08 AM