我要問有關C#中的問題,Asp.net ...我在3文本框爲EMPID,姓名和地址分配的GridView值文本框中
如果我點擊「編輯按鈕」與在文本框中手動輸入empid。我想分配其他兩個值名稱&地址到他們的文本框。然後我使用更新按鈕更新
任何人都可以教我與代碼?
//Asp.net
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Empid" Width="50px"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Name" Width="50px"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="Address" Width="50px"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<br />
<br />
<br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<br />
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="update " />
<asp:Button ID="Button2" runat="server" Text="Edit" Width="61px" />
</form>
//Cs for update button
SqlConnection conn = new SqlConnection("Data Source=s\\SQLEXPRESS;Initial catalog = sample;Integrated security=True");
SqlCommand cmd = new SqlCommand("UPDATE empdetails SET Name='" + TextBox2.Text + "',Address='" + TextBox3.Text + "' WHERE Empid ='" + TextBox1.Text + "'", conn);
conn.Open();
cmd.ExecuteNonQuery();
cmd.CommandText = "SELECT * FROM Empdetails";
GridView.DataSource = cmd.ExecuteReader();
GridView.DataBind();
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
conn.Close();
我這樣的代碼,如果我編輯按鈕,用輸入EMPID,我想其他值命名&地址會分配到文本框中
哈哈大聲笑,告訴我們你試過了什麼:D –
請發表一些你已經嘗試過的代碼。 –
通過ajax調用發送empid到服務器頁面,從服務器獲取數據名稱和地址,並在成功時顯示它。 – SeeTheC