将html无序列表值传递给c#文本框并在sqlquery中使用
本文关键字:sqlquery 文本 无序 html 列表 值传 | 更新日期: 2023-09-27 18:13:25
这是我用来将文本设置为特定值的javascript
document.getElementById('Original Map').addEventListener('click', function () {
map.setView([52.42922, -18.5154], 5);
var text = document.getElementById("mytext");
text.value = "Original Map";
});
这是html
<form id="Form1" runat="server" >
<ul>
<li>
<li><label><h5>Now Selected: </h5></label>
<asp:TextBox ID="mytext" runat="server" ReadOnly style=" font-size:15px; border:0px; " BackColor="White" ForeColor="#6699FF"></asp:TextBox></li>
<li><asp:Button ID="Button2" runat="server" Text="Button" style ="border-radius:5px; width:100px; padding:5px;" class="btn btn-primary" OnClick="Button1_click" /></li>
</li>
</ul>
<asp:GridView ID="GridView1" runat="server" BackColor="White" AlternatingRowStyle-BackColor="Black" BorderColor="White">
</asp:GridView>
</form>
这是c#代码
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:'Users'mduggan'Documents'Database1.accdb");
public string TextBoxValue
{
get { return mytext.Text; }
set { mytext.Text = value; }
}
protected void Button1_click(object sender, EventArgs e)
{
filldata();
}
protected void filldata()
{
string query;
query = TextBoxValue;
if (query != null)
{
con.Open();
string str = "SELECT PageID, PageName FROM Maps WHERE PageName ='" + query + "'";
OleDbCommand cmd = new OleDbCommand(str, con);
OleDbDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
}
else
{
Label1.Visible = true;
}
}
为什么查询变量(在。cs类中)不从HTML无序列表中拾取TextBoxValue值。
列表中的值被转移到文本框中,但是随后查询变量没有检测到文本框中的任何值,并且在返回的sqlquery
这可能是因为您的文本框设置为只读,这可能导致对象在单击时不会被发送回服务器。来源:http://weblogs.asp.net/anasghanem/how-to-get-the-readonly-textbox-value-on-the-server