How can I get the ID of the selected item from the input list. I can fetch the item but can not fetch the ID of the selected item.
<div class="form-row">
<label>
<span> Selected Items</span>
<input list="username" runat="server" id="usernameInput" class="form-control input_list" placeholder="FACULTY" required="required" />
<datalist id="username" runat="server"></datalist>
</label>
</div>
<div class="form-row">
<label>
<span> Selected HTML5 Input</span>
<input type="text" id="input_selected" runat="server" />
</label>
</div>
<div class="form-row">
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</div>
I want to display USER_NAME in the input list to the user but want to fetch USER_ID of the selected USER_NAME in the codebehind page.
public void GetUserName()
{
string strQuery = "SELECT USER_ID, USER_NAME FROM TBL_USER";
SqlCommand cmd = new SqlCommand(strQuery);
DBConnection conn_ = new DBConnection();
DataTable dt = conn_.SelectData(cmd);
var builder = new System.Text.StringBuilder();
for (int i = 0; i < dt.Rows.Count; i++)
{
builder.Append(String.Format("<option value='{0}'>", dt.Rows[i][1]));
}
username.InnerHtml = builder.ToString();
usernameInput.Attributes["list"] = username.ClientID;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
input_selected.Value = usernameInput.Value;
}
This gives me the USER_NAME but I want to fetch USER_ID in the code behind page. How can I do that?