|
The images are not in the database yet. They are stored in the path mentioned, so far,
and i'm trying to figure out a way to store them in the database. The code i posted
in my first post does not work and i couldn't debug it. I'm looking for the appropriate
corrections to make on my code so that my application will store the images in the database
or write new code from scratch if there is a better way to do this.
Thanks!
|
|
|
|
|
|
Hi!
I have used Editable Gridview control in which I have put Add category button,On the above of control
The first column of grid view is primary key ProductId and sec. is productname. On the Product name I have replace Hyperlink in place of bound contol. so on the click i can navigate on some other page the problem is that when I click on add button the Hyperlink can not change in the bound control so i cant got the Textbox and so its give the following error.
"Unable to cast object of type 'System.Web.UI.WebControls.HyperLink' to type 'System.Web.UI.WebControls.TextBox'."
<br />
<br />
if (((LinkButton)GridView1.Rows[0].Cells[2].Controls[0]).Text == "Insert")<br />
{<br />
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MYConnectionString"].ConnectionString);<br />
SqlCommand cmd = new SqlCommand();<br />
cmd.CommandText = "INSERT INTO Products(cat_name) VALUES(@cat_name)";<br />
cmd.Parameters.Add("@cat_name", SqlDbType.VarChar).Value = ((TextBox)GridView1.Rows[0].Cells[1].Controls[0]).Text;<br />
cmd.Connection = con;<br />
con.Open();<br />
cmd.ExecuteNonQuery();<br />
con.Close();<br />
}<br />
modified on Tuesday, March 18, 2008 4:13 PM
|
|
|
|
|
The error message tells you all you need to know. GridView1.Rows[0].Cells[1].Controls[0] is a HyperLink, not a TextBox control.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
pmarfleet wrote: The error message tells you all you need to know.
Except for not using inline SQL statements
only two letters away from being an asset
|
|
|
|
|
But I want to put textbox run time when I click on add category button so the entire new row comes up in the grid and the cells automatically convert into textbox control after filling up controls when i click insertlabel from one the cell.and then it will automatically again convert in the hyperlink rather then a normal text....
|
|
|
|
|
I have absolutely no idea what you are asking
only two letters away from being an asset
|
|
|
|
|
|
Read the answers you have already been given and stop wasting our time.
only two letters away from being an asset
|
|
|
|
|
Ya solve the problem ,But I have a question when I have used command button in the gridview now when i
click the "Insert" for new record the linkbutton every time use the "update" action so rather then inserting new record.
what should I do?
I had debug the application and explicitly put the value then it takes but when i use routine its default takes "Update" every time.
Please look at little code for understanding.
when click on addbutton
protected void btnAdd_Click(object sender, EventArgs e)<br />
{<br />
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MYConnectionString"].ConnectionString);<br />
SqlDataAdapter da = new SqlDataAdapter("SELECT subcat_id,subcatename,description,Pid FROM Subcatagory", con);<br />
DataTable dt = new DataTable();<br />
da.Fill(dt);<br />
<br />
DataRow dr = dt.NewRow();<br />
dt.Rows.InsertAt(dr, 0);<br />
GridView1.EditIndex = 0;<br />
GridView1.DataSource = dt;<br />
GridView1.DataBind();<br />
<br />
<br />
((LinkButton)GridView1.Rows[0].Cells[5].Controls[0]).Text = "Insert";<br />
Session["operation"] = "Insert"; <br />
<br />
}<br />
<br />
When control leaves the scope it automatic use "Update"<br />
For row updating
<br />
<br />
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)<br />
{<br />
<br />
<big><br />
<br />
if (((LinkButton)GridView1.Rows[0].Cells[5].Controls[0]).Text == "Insert" || Session["operation"] == "Insert")<br />
{<br />
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MYConnectionString"].ConnectionString);<br />
SqlCommand cmd = new SqlCommand();<br />
cmd.CommandText = "INSERT INTO Subcatagory(subcatename,description,Pid) VALUES(@subcatename,@description,@Pid)";<br />
cmd.Parameters.Add("@subcatename", SqlDbType.VarChar).Value = ((TextBox)GridView1.Rows[0].Cells[2].Controls[0]).Text;<br />
cmd.Parameters.Add("@description", SqlDbType.VarChar).Value = ((TextBox)GridView1.Rows[0].Cells[4].Controls[0]).Text;<br />
cmd.Parameters.Add("@Pid", SqlDbType.Int).Value = Int32.Parse(Request.QueryString["Pid"]); <br />
cmd.Connection = con;<br />
con.Open();<br />
cmd.ExecuteNonQuery();<br />
con.Close();<br />
<br />
}<br />
else<br />
{<br />
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MYConnectionString"].ConnectionString);<br />
SqlCommand cmd = new SqlCommand();<br />
cmd.CommandText = "UPDATE Subcatagory SET subcatename=@subcatename,description=@description WHERE subcat_id=@subcat_id";<br />
cmd.Parameters.Add("@subcatename", SqlDbType.VarChar).Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;<br />
cmd.Parameters.Add("@description", SqlDbType.VarChar).Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;<br />
cmd.Parameters.Add("@subcat_id", SqlDbType.Int).Value = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[1].Text);<br />
cmd.Connection = con;<br />
con.Open();<br />
cmd.ExecuteNonQuery();<br />
con.Close();<br />
}<br />
<br />
<br />
GridView1.EditIndex = -1;<br />
BindData();<br />
}<br />
<br />
<br />
<br />
|
|
|
|
|
I've just created a FormView (my first, so bare with me please), with a default mode of "Insert", bound to a SQL Server database. When I click the Insert button, the ItemInserting event fires on the FormView, but not on the SqlDataSource. I'm guessing this may be data related, but no exception is thrown. Any suggestions?
|
|
|
|
|
My bad. Even in VS 2008, I still get the extremely rude behaviour of the designer totally wiping my FormView and generating templates when I set the DataSourceID, so I work around by copying my template, setting DataSourceID, and pasting my template back. So, pasting the original template back wiped the DataSourceID.
|
|
|
|
|
Hi all
I have a user privilages form, How can I make a checkbox that checks all the checkboxes in a form ?
Thanks
Nour Abdel-Salam...
A Trainer and a Web Developer in Jedda Int'l Computer Center(JICC)
|
|
|
|
|
There are several ways, client-side JavaScript to server-side events. Clarify your requirements and you may get a more precise answer.
only two letters away from being an asset
|
|
|
|
|
Hi Mark
I prefer to get the server side events if it possible..
Regards
Nour Abdel-Salam...
A Trainer and a Web Developer in Jedda Int'l Computer Center(JICC)
|
|
|
|
|
Checkboxes has a CheckedChange event where you can verify if that checkbox is checked or not, and you check or uncheck the other checkboxes.
You can use Ajax Update panel if you want to do this without refreshing your page
Ex:
protected void allTotals_CheckedChanged(object sender, EventArgs e)
{
if (allTotals.Checked)
{
customTotals1.Checked = false;
customTotals2.Checked = false;
customTotals3.Checked = false;
customTotals4.Checked = false;
....
}
else
{
customTotals1.Checked = true;
customTotals2.Checked = true;
customTotals3.Checked = true;
customTotals4.Checked = true;
....
}
}
--------------------------------
visit: http://pmartike.deviantart.com/
|
|
|
|
|
More efficient code
protected void allTotals_CheckedChanged(object sender, EventArgs e)<br />
{<br />
customTotals1.Checked = allTotals.Checked;<br />
customTotals2.Checked = allTotals.Checked;<br />
customTotals3.Checked = allTotals.Checked;<br />
customTotals4.Checked = allTotals.Checked;<br />
}
Or even better yet, put the checkboxes in a container
protected void allTotals_CheckedChanged(object sender, EventArgs e)<br />
{<br />
foreach(CheckBox c in Panel1.Controls)<br />
c.Checked = allTotals.Checked;<br />
}
only two letters away from being an asset
|
|
|
|
|
Thanks alot sir
and how can I do it using Javascript?
Regards
Nour Abdel-Salam...
A Trainer and a Web Developer in Jedda Int'l Computer Center(JICC)
|
|
|
|
|
hello
i am begin to study object programming and the pattern and practices
in this moment i have a small project in my work
i am trying to implement pattern and practices
the application is about send email
and before this have to apply business rules
for example
rule 1 the client have to car model xxxx
rule 2 the client have to 55 years old
rule 3 etc
i have a dataset and i apply function 1 (business rule 1)
ds = applyrule1(parameter)
and to apply rule 2 i send the dataset how parameter to function 2
ds = applyrule2(ds)
ds = applyrule3(ds)
ds = applyrule4(ds)
and i have
Private Function applyrule1(ByVal ds As DataSet) As DataSet
.
.
.
.
.
.
end function
Private Function applyrule1(ByVal ds As DataSet) As DataSet
.
.
.
.
.
.
end function
the function same equal
i work with pattern and practices some one tellme a guide to Implemment pattern and practices to mi case project
thanks
|
|
|
|
|
|
|
Hi!
I have a question. How can i redirect to another page in a Button_click event. If i try with Response.Redirect("test.aspx") on test.aspx i get null values Request.Form("...") . If i try with Server.Transfer("...") i get an error:
"Sys.Webforms.PageRequestManagerParserErrorException:The message recieved from the server could not be parsed. Common causes for this error are when the response is modified by calls Response.Write(),response filters,HttpModules,or server trace is enabled. Details error parsing near ' y code:
<br />
protected void OkBTN_Click(object sender, ImageClickEventArgs e)<br />
{<br />
if (startDate <= endDate) Server.Transfer("test.aspx");<br />
else<br />
{<br />
messageLbl.Text = dateError;<br />
messageLbl.Visible = true;<br />
}<br />
}<br />
I just want to redirect to my test.aspx page and get some values with Request.Form().
Plese help me
Thank you!
Regards,
Marta Paniti.
--------------------------------
visit: http://pmartike.deviantart.com/
|
|
|
|
|
try Response.redirect(url?variables)
|
|
|
|
|
I'm sorry but i have a lot of controls on my first page... i can't transfer all those values like this
--------------------------------
visit: http://pmartike.deviantart.com/
|
|
|
|
|
Server.Transfer("test.aspx", true);
true to preserve the QueryString and Form collections; false to clear the QueryString and Form collections.
only two letters away from being an asset
|
|
|
|