4月 02, 2014

MVC 用表單送資料給資料庫

首先是View
    @{Html.BeginForm("postdata", "home", FormMethod.Post);}
    @Html.Label("hh")<br>
    First name: <input id="textbox1" name="name1" type="text" value=""><br>
    Last name:  @Html.TextBox("name2", "", new {id="textbox2" })
    <br>
    <input id="Submit11" type="submit" value="submit" />
    @{Html.EndForm();}
再來是controll
        [HttpPost]
        public ActionResult postdata(int name1,int name2)
        {
            //ViewData["result"] = name1 + name2;
            //ViewBag.da = name1 + name2;
            int hh = name1 + name2;
            ty.see56(hh);
            return RedirectToAction("Index");
        }
接著是Model
 public int see56(int vlk)
        {

            SqlDataSource sds = new SqlDataSource();
            sds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            sds.UpdateCommand = "update item set mp=@mp where id=1";
            sds.UpdateParameters.Add(new Parameter("mp",DbType.String,vlk.ToString()));
            sds.Update();
            
           
            return 0;
            //return dv.Table.Rows[2].ItemArray[1].ToString();
        }
大功告成!

4月 01, 2014

設計換行和超聯結

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Label1 As Label = FormView1.FindControl("Label1")
        'Dim b As String = vbNewLine
        'Replace(a.Text, Chr(10), "<br />")
        If Label1 IsNot Nothing Then

            Label1.Text = Replace(Label1.Text, vbNewLine, "<br />")

        End If

        ads_count.Update()

    End Sub

    

    Protected Sub HyperLink2_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim a As HyperLink = FormView1.FindControl("HyperLink2")
        'Server.Transfer("./upload/" + a.Text)
        'Response.Redirect("./upload/" + a.Text)
        Dim b As String = "./upload/" + a.Text

        a.NavigateUrl = b

    End Sub