我有一个文本框可以输入条形码和搜索按钮。该按钮将显示一个单选按钮列表,其中包含3个与服务器条形码相关的数据块。
sheetDetail.aspx
<div>
<span>Enter Barcode: </span>
<asp:TextBox runat="server" ID="txtSearch" />
<asp:Button runat="server" ID="btnSearchBar" Style="background-color: #c9302c;" CssClass="btn btn-danger" Text="Search" OnClick="btnSearchBar_Click" />
<asp:RadioButtonList Font-Size="X-Small" RepeatLayout="Table" RepeatColumns = "2" ID="rediobtn" runat="server">
</asp:RadioButtonList>
</div>
sheetDetail.aspx.cs
protected void btnSearchBar_Click(object sender, EventArgs e)
{
eExistingSheetQuery existingSheetQuery = new eExistingSheetQuery();
string value = txtSearch.Text.Trim();
// Your Ado.Net code to get data from DB
rediobtn.Items.Clear();
DataTable dt = existingSheetQuery.GetSheetItem(value);
rediobtn.DataSource = existingSheetQuery.GetSheetItem(value);
rediobtn.DataBind();
}
eExistingSheetQuery.cs
public DataTable GetSheetItem(string barcode)
{
try
{
conn = new SqlConnection(estocktake);
conn.Open();
DataTable dtd = new DataTable();
GridView gvd = new GridView();
cmds = new SqlCommand(@"SELECT [invtid],[transtatuscode] ,[descr] FROM [Products] where ib_itemcode1='" + barcode + "' ;", conn);
adpt = new SqlDataAdapter();
adpt.SelectCommand = cmds;
cmds.ExecuteNonQuery();
adpt.Fill(dtd);
conn.Close();
conn.Dispose();
return dtd;
}
catch (Exception)
{
conn.Close();
conn.Dispose();
return null;
}
}
该按钮将触发onclick
,该功能将开始运行,从文本框中获取值。
getsheetitem
- &gt;运行查询并获取数据
将其绑定到gridview ...
显示的全部是System.Data.DataRowView。所有的收音机都是......
我想要显示每个单选按钮。
[radiobutton] invtid - descr - transtatuscode
任何帮助都会非常棒。
答案 0 :(得分:0)
请尝试使用sheetDetail.aspx.cs
protected void btnSearchBar_Click(object sender, EventArgs e)
{
eExistingSheetQuery existingSheetQuery = new eExistingSheetQuery();
string value = txtSearch.Text.Trim();
// Your Ado.Net code to get data from DB
DataTable dt = existingSheetQuery.GetSheetItem(value);
rediobtn.Items.Clear();
rediobtn.Items.Add(Rows[0]["invtid"]);
rediobtn.Items.Add(Rows[0]["transtatuscode"]);
rediobtn.Items.Add(Rows[0]["descr"]);
}
答案 1 :(得分:0)
我相信您正在获取System.Data.DataRowView,因为您尚未定义DataTextField,即
rediobtn.DataTextField = "transtatuscode";
rediobtn.DataValueField = "invtid";
rediobtn.DataBind();
如果要将所有这些字段组合在一起,可以更改查询以将这三个字段连接在一起。
答案 2 :(得分:0)
谢谢大家的帮助,我想出的解决办法是对这样的查询进行所有更改。
cmds = new SqlCommand(@"SELECT [invtid] +' '+ [descr] +' '+ [transtatuscode] as ProductDesc FROM [Products] p where ib_itemcode1='" + barcode + "' ;", conn);
这样,数据在绑定到表之前就已经合并了。