我想在asp.net中创建事件并在选择文本更改时调用它 [英] I want to create event in asp.net AND call it on selection text change
问题描述
DataTable dtToGrid = (DataTable)Session["dtToGrid"];
dtToGrid = select.SelectData(SefatyStockSelectSearch, ddl_Inv_IndentID.SelectedValue.ToString());
GridView1.DataSource = dtToGrid;
GridView1.DataBind();
这是绑定gridview代码
select.selectData是dll文件它在页面加载时工作,但我想调用下拉列表的文本更改事件
即使数据库已有记录
我想要显示dropdownlist的每个文本更改
this is binding gridview code
select.selectData is dll file it work on page load but i want to call text change event of dropdownlist
even though database has present record
and i want to show on every text change of dropdownlist
推荐答案
1.您不应该缓存用于GridView的数据表
在会话
内,因为只有一些非常重要的信息应该缓存在那里(如用户ID)。请注意,在数据绑定后GridView
的情况下,数据将缓存在回发之间的网格中。
2.要根据下拉列表更改的选择索引过滤网格视图中的数据,您应该设置AutoPostBack =true
为您的下拉列表,然后使用事件OnSelectedIndexChanged
。详情请见此处。 [ ^ ]
3.通常在网格视图中,如果您有大量数据,则必须使用分页。您可以在我的下一篇文章中找到有关此内容的详细信息,以及有关使用GridView
控件的信息:高级ASPX GridView分页和数据实体 [ ^ ]
1.You should not cache the data table used for yourGridView
inside theSession
, because only some very important info should be cached there (like user ID). Note that in the case ofGridView
after data binding the data will be cached in the grid between post backs.
2.To filter the data in the grid view based on selection index changed of the drop down list you should setAutoPostBack="true"
for your drop down list, then use the eventOnSelectedIndexChanged
. See details here.[^]
3.In generally in a grid view, if you have a big amount of data you have to use pagination. You could find details about this, and also about usingGridView
control in my next article: Advanced ASPX GridView Pagination and Data Entities[^]
检查本地IP地址[C#]
此示例显示如何检测主机名或IP地址是否属于本地计算机。
获取本地计算机名
使用静态方法获取本地计算机主机名Dns.GetHostName。
[C#]
Check Local IP Address [C#]
This example shows how to detect whether a host name or IP address belongs to local computer.
Get local computer name
Get local computer host name using static method Dns.GetHostName.
[C#]
string localComputerName = Dns.GetHostName();
获取本地IP地址列表
使用静态方法Dns.GetHostAd-dresses获取计算机IP地址列表。要获取本地IP地址列表,请将本地计算机名称作为方法的参数传递。
[C#]
Get local IP address list
Get list of computer IP addresses using static method Dns.GetHostAd¬dresses. To get list of local IP addresses pass local computer name as a parameter to the method.
[C#]
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
检查IP地址是否为本地
以下方法检查给定的主机名或IP地址是否为本地。首先,它获取给定主机的所有IP地址,然后获取本地计算机的所有IP地址,最后比较两个列表。如果任何主机IP等于任何本地IP,则主机是本地IP。它还检查主机是否是环回地址(localhost / 127.0.0.1)。
[C#]
Check whether an IP address is local
The following method checks if a given host name or IP address is local. First, it gets all IP addresses of the given host, then it gets all IP addresses of the local computer and finally it compares both lists. If any host IP equals to any of local IPs, the host is a local IP. It also checks whether the host is a loopback address (localhost / 127.0.0.1).
[C#]
public static bool IsLocalIpAddress(string host)
{
try
{ // get host IP addresses
IPAddress[] hostIPs = Dns.GetHostAddresses(host);
// get local IP addresses
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
// test if any host IP equals to any local IP or to localhost
foreach (IPAddress hostIP in hostIPs)
{
// is localhost
if (IPAddress.IsLoopback(hostIP)) return true;
// is local address
foreach (IPAddress localIP in localIPs)
{
if (hostIP.Equals(localIP)) return true;
}
}
}
catch { }
return false;
}
您可以测试方法,例如:
[C#]
You can test the method for example like this:
[C#]
IsLocalIpAddress("localhost"); // true (loopback name)
IsLocalIpAddress("127.0.0.1"); // true (loopback IP)
IsLocalIpAddress("MyNotebook"); // true (my computer name)
IsLocalIpAddress("192.168.0.1"); // true (my IP)
IsLocalIpAddress("NonExistingName"); // false (non existing computer name)
IsLocalIpAddress("99.0.0.1"); // false (non existing IP in my net)
private string ReturnIPAddress()
{
IPHostEntry host;
string localIP = "?";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
localIP = ip.ToString();
}
}
return localIP;
}
这篇关于我想在asp.net中创建事件并在选择文本更改时调用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!