控制以填充数据并执行回发(control to fill the data and perform postback)

   IT问题网   2020-06-27 00:00:00

问 题

嗨,

是否有任何控制来填充数据库中的数据并执行回发操作。

我想从我的数据库中填写一个字段,然后选择选中的字段应显示在文本框中。

解决方案

您好,



您可以使用任何数据控件来自基本的asp.net控件



你可以看到工具箱中的数据控件列表,如..datalist,reapeter,gridview ...





并编写代码以在selectedindexchanged事件中显示数据





http://msdn.microsoft.com/en-us/library/cc295567.aspx



在上面的链接中,您可以看到有关数据控件的详细信息



 lt;   form     id   ="  form1"    runat   ="  server" gt;  
lt; p gt;
lt; br / gt;
lt; asp:textbox id =" textbox1" runat =" server" gt; lt; br / gt;
lt; asp:datalist id =" datalist1" runat =" server" onitemcommand =" datalist1_itemcommand" 宽度 =" 60% "
gt;
lt; headertemplate gt;
lt; table width =" 100%" align =" center" gt;
lt; tr gt;
lt; td gt; 项目列表lt; / td gt;
lt; / tr gt;

lt; / headertemplate gt;
lt; itemtemplate gt;
lt; tr gt;
lt; td gt;
lt; asp:linkbutton id =" linkbutton1" runat =" server" commandname =" show" commandargument =" 3" gt; lt; asp:label id =" label1" runat =" server" text =' lt;% #container.dataitem% gt;' gt;

lt; / td gt;
lt; / tr gt;
lt; / itemtemplate gt;
lt; footertemplate gt;
lt; / footertemplate gt; lt; / table gt;



lt; / p gt;
lt; / form gt;




文件后面的代码包含以下代码



 受保护  void  page_load ( object  sender,eventargs e)
{
if (!ispostback)
{


listlt; stringgt; str = new listlt; stringgt;();
str.add(" frstitem");
str.add(" secnditem");
str.add(" ghgfh");
str.add(" frstitem");
str.add(" secnditem");
str.add(" ghgfh");
str.add(" frstitem");
str.add(" secnditem");
str.add(" ghgfh");

datalist1.datasource = str;
datalist1.databind();


}
}

受保护 void datalist1_itemcommand( object source,datalistcommandeventargs e)
{
if (e.commandname == " show"
{
label lbl =(label)e.item.findcontrol(" label1");
textbox1.text = lbl.text;
}
}
lt; / string gt; lt; / string gt;




在上面的示例中,我们可以按照旧方法将数据库设置为datalist





所有最佳

标签:控制节制填充数据执行履行



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

System()vs CreateProcess()vs ShellExecute()(System() vs CreateProcess() vs ShellExecute())

problem here''s one for everyone, i''m running a batch fi ...

将TCL代码转换为C ++ ...(Convert a TCL code to C++...)

problem for {set i 128} {$ilt;256} {incr i 1} { eval lut ...

如何从二进制文件中读取浮点值(How Read Float value from Binary File)

problem hi. i do want to read float value from binary fi ...

使用.bak文件还原数据库(Restore Database using.bak file)

problem good evening everybody, please say how to restor ...

在gridview中显示总和(Show sum In gridview)

problem my gridview has data which looks like below (for ...

Ajax客户端脚本错误(Ajax Client side script error)

problem if (typeof(sys) === #39;undefined#39; ...

如何在UP和DOWN键进行编码(How to code at the UP and DOWN key)

problem i want to move picture box up and down when a use ...

如何计算excel 2003中的时间平均值(how to calculate time averge in excel 2003)

problem hii to all. if any body knows how to calculateave ...

控制相关问题(Control related issue)

problem respected sir, i have a page in which i m gettin ...

在运行时动态绘制div(draw div dynamically at runtime)

problem hiii all, i have a page which i draw all its attr ...

转换数据库值(Convert a databse value)

problem i have a table one field is price and ...

如何使单元格的内容可见为false(How do i make the content of a cell visible false)

problem how do i make the content of a cell visible false ...

qtwebkit并连接cpp和javascript(qtwebkit and connect cpp and javascript)

problem hi to all i am using qwebkit i have a cpp object ...

response.flush&到Response.End(problem with response.flush & response.end)

problem hello everybody, i have used response.flush() wi ...

ShellExecute()不执行(ShellExecute() Not Executing)

problem i''m running a batch file from c++ code.when i ru ...

Radion Button使用Javascript隐藏/可见(Radion Button Hide/Visible Using Javascript)

problem i want hide/visible radio button using javascript ...

如何在此xml文件中插入/删除节点(how to insert/delete a node to this xml file)

problem hi all :) i search in webto find a code that ins ...

XML + DTD,不会出现在浏览器中(XML + DTD, won't show up in browser)

problem my code looks right, validates, but when i open i ...

什么是样品反射(What is Reflection with sample)

problem hi everybody, could u plz tell me reflection d ...

在封闭网络上获取设备的IP地址(optaining IP addresses of devices on a closed network)

problem i have a situation where i have multiple devices ...