如何使用sendkey + C#将数据发送到下拉控件中 [英] how to send data into dropdown control using sendkey + C#

查看:74
本文介绍了如何使用sendkey + C#将数据发送到下拉控件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我正在做一个Windows应用程序,其中使用了Web浏览器控件,用于连接URL的按钮,用于表单中搜索数据的文本框.我将Web浏览器控件导航到dataentry网站之一.我的数据库中有数据,例如姓名,地址城市,dbo,地区等.
我正在做什么,我按照名称标准从数据库中搜索数据并获取数据集中的所有值,然后使用``SendKey''将搜索到的数据发送到网站的特定字段,它也可以工作.问题是它适用于文本框网站的控件,但不用于下拉列表控件.我使用"Tab"键发送数据.该网站对城市,州,国家,性别等使用下拉控件.每当我从下拉控件中选择某些项目时,它每次都会回发并每次都加载页面.为了避免在网站中进行回发和重新加载,我尝试制作此应用程序.

以下是我的密码:

Hello
I m doing one windows application where i used web browser control,button for connecting URL, textbox for search data in my form. I navigate webbrowser control to one of the dataentry website. I have the data in my database like name, address city, dbo, district etc.
what i m doing i search data from database on name criteria and getting all values in dataset then using ''SendKey'' i send that searched data to the particular fields of the website and it works also.The problem is that it works for the textbox control of the website but not for the dropdown control. I used the ''Tab'' key for sending data.That website Using Dropdown Control for City,State,Country, Gender etc. Whenever i select some item from dropdown control it postback every time and load page every time. To avoid postbacking and reloading in website i try to make this application.

Below is My COde:

private void fillData()
{
 //Code for searching the record against 'CustomerName'
         if (dSet.Tables[0].Rows[0]["DistrictName"] != DBNull.Value)         //Dropdown Control
         SendKeys.Send(dSet.Tables[0].Rows[0]["DistrictName"].ToString().Trim());
         WaitFor();
         SendKeys.Send("{TAB}");
         SendKeys.Send(dSet.Tables[0].Rows[0]["City"].ToString().Trim());
         WaitFor();
        SendKeys.Send("{TAB}");
        SendKeys.Send(dSet.Tables[0].Rows[0]["SpouseName"].ToString().Trim()); //Textbox Control
        WaitFor();
        // and So Many Fields..
       WaitFor();
       GC.Collect();
}

private void WaitFor()
        {
            for (int i = 0; i <= 5000; i++)
            {
                Application.DoEvents();
                Application.DoEvents();
                Application.DoEvents();
                Application.DoEvents();
                Application.DoEvents();
            }
        }


请帮助我完成下拉控件中发送数据的操作.

问候
Maahi


Plz help me out what i do for sending data in dropdown control.

Regards
Maahi

推荐答案

您的代码是Windows窗体,而不是asp.net.尝试将那些控件的CauseValidation设置为false.

祝你好运!
Your code is windows forms and not asp.net. Try set CauseValidation to false for those controls.

Good luck!


这篇关于如何使用sendkey + C#将数据发送到下拉控件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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