选择一个列表项并使用sql查询显示相应的结果 [英] select a list item and use an sql query to display the corresponding result

查看:54
本文介绍了选择一个列表项并使用sql查询显示相应的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何从列表框中选择特定项目,然后执行sql查询以显示特定结果?

我对即时通讯应该在哪里写这个SQL查询感到困惑..

Hi,

How do i select a particular item from a list box and then execute an sql query to display the particular result?

im confused as to where im supposed to write this sql query..

推荐答案

将其用于列表框
增强的列表框控件
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listbox.aspx
从列表框中获取所选项目

Refer this for listbox
Enhanced List Box Control
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listbox.aspx
Get Selected item from listbox

int numberSelected = listBox1.SelectedItems.Count;

   for (int i = 0; i < numberSelected; i++)
   {
       ListItem li = (ListItem)listBox1.SelectedItems[i];
       //sql query - pass li.value to query
  }


这样做:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if(listBox1.SelectedIndex > -1)
    {

       object selectedValue = listBox1.SelectedValue;
      // I advise you to unbox listbox's selected value to it's proper type
      //i.e. if it is type of int
      //int selectedValue = (int) listBox1.SelectedValue;

      //query code (or call to a method with query code) goes  here      
    }
}



祝你好运!



Good luck!


我想,你在谈论Windows应用程序.

您需要选择列表框的selectedItem并从中获取文本.
使用事件Listbox的SelectedIndexChanged.

I think, you are talking about Windows application.

You need to select the selectedItem of the listbox and get the Text from it.
Use the event, SelectedIndexChanged of Listbox.

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    //get the selectd text

    // The variable that will keep the index of the selected item
    int index;
    // Get the index of the selected item
    index = listBox1.SelectedIndex;

    //get the selected text
    string selectedText = string.Empty;
    if (index >= 0)
    {
        selectedText = listBox1.GetItemText(listBox1.Items[index]).ToString();


      //write your sql and pass the text as one parameter
      //do sql stuff

      //get the data and show it in any controls like gridview or whatever you want to do with data

    }
}



希望这会有所帮助.
欢呼



Hope this helps.
cheers


这篇关于选择一个列表项并使用sql查询显示相应的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆