在datagrid里面,我用了模版列,里面放一个label,我想把一个数据库里的一列IP 数据通过函数longtoipaddr()转化后邦定到这个 label上,可是不知道怎么弄,我写了点代码,label的数据只是数据库中的第一条数据,
请给我更正,尽量写细一点,我水平低
string sec="select * from iphdr ";
SqlConnection conn=new SqlConnection("Server=127.0.0.1;database=snort;uid=sa;password=sa;");
conn.Open();
SqlCommand cmd=new SqlCommand(sec,conn);
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
ip1=dr[2].ToString();
ip2=longtoipaddr(ip1);
}
ip_dg.DataSource=dr;
ip_dg.DataBind();
dr.Close();
conn.Close();
请给我更正,尽量写细一点,我水平低
string sec="select * from iphdr ";
SqlConnection conn=new SqlConnection("Server=127.0.0.1;database=snort;uid=sa;password=sa;");
conn.Open();
SqlCommand cmd=new SqlCommand(sec,conn);
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
ip1=dr[2].ToString();
ip2=longtoipaddr(ip1);
}
ip_dg.DataSource=dr;
ip_dg.DataBind();
dr.Close();
conn.Close();
解决方案 »
- asp.net分页
- ASP.NET发送邮件报错问题??
- ASP.NET AJAX的菜鸟问题
- .cs怎么对应.aspx.cs
- asp.net程序在调试的时候,正常运行,但是,在iis中,却有时候点击一些linkbutton,没有反应,怎么回事....
- 如何向向数据库中存储日期!
- 100分求教一句SQL语句
- 请教:下载文件要求输入用户名密码问题(急)(解决就送100分)
- asp.net开发:单击DataGrid能把当前行的记录分别放到上面的TextBox中。
- 为什么我用asdl连接总是报搓
- 用WebClient类从服务器下载文件时,如何先检测服务器该文件是否存在?急!!
- 各位老大,我引用我的控件为什么会出错拉?
在后台写个函数public string longtoipaddr(string ip1){};注意一定要public在前台模板列中
<asp:Label id="lblIp" runat="server"><%# longtoipaddr(DataBinder.Eval(Container.DataItem,"pnr")) %></asp:Label>
即可
方法有好几种,第一种:
在后台写个函数public string longtoipaddr(string ip1){};注意一定要public在前台模板列中
<asp:Label id="lblIp" runat="server"><%# longtoipaddr(DataBinder.Eval(Container.DataItem,"ip1")) %></asp:Label>注:ip1就是你数据库中要转换的字段名
即可
增加一列ip2,ip2=longtoipaddr(ip1);
在label中绑定ip2就行了