TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Aktham Mahmoud
NA
720
38.1k
Unable to cast a dropdownlist in GridView and Convertible
Jan 30 2020 5:21 AM
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
Unable to cast object of type 'System.Web.UI.WebControls.DropDownList' to type 'System.IConvertible'.
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;
}
}
Reply
Answers (
6
)
Failed to load resource: net::ERR_EMPTY_RESPONSE Error
How to use local db for publish a site