2012-02-21 60 views
0

我想将中继器控制值存储到数据库表中。我有一个与相应的文本框三个标签的中继器控制。如何将中继器控制值存储到数据库中

<asp:Repeater ID="RepeatInformation" runat="server"> 
<ItemTemplate> 
    <tr> 
     <td valign="top" class="style3"> 
     <%#DataBinder.Eval(Container,"DataItem.fldleavename")%> 
     </td> 
     <td valign="top"> 
      <asp:TextBox ID="TextBox1" runat="server" CssClass="textbox" ></asp:TextBox> 
     </td> 
    </tr> 
</ItemTemplate> 
</asp:Repeater> 

Repeater控件格式:

Casual Leave : Textbox1 
    Medical Leave : Textbox1 
    Annual Leave : Textbox1 

我怎么可以存储转发值数据库。我没有想法存储这个值请帮助我..

回答

0
foreach (RepeaterItem item in RepeatInformation.Items) 
{ 
    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) 
    { 
     TextBox textBox = (TextBox)item.FindControl("TextBox1"); 

     //Now you have your textbox to do with what you like 
     //You can access the .Text property to find the new value that needs saving to the database 
    } 
} 

在旁注中。我会考虑修改你的控件的名称。如果您采用某种惯例并使用骆驼案例,它将使未来的生活变得更容易。

关于将其保存到数据库 - 完全取决于您目前如何处理数据访问。我认为这是另一个问题。

0

您可以将值存储在列表对象&然后绑定到数据库中的数据表。

+0

认罪代表控制 //获取数据给出一个示例代码.. – Fernando 2012-02-21 11:28:59

0

修改您的数据表,并使用SqlDataAdapter的

更新到数据库
-1

enter code here 保护无效repeater_ItemDataBound(对象发件人,RepeaterItemEventArgs E) { 如果(e.Item.DataItem强制转换!= NULL){ // 创建对象数据库 //使用e.Item //将它变成数据库 }}

+0

他为什么要将数据绑定上的文本框的值存储到数据库中?如果我理解操作系统将数据绑定到数据库的方式,它将会'重新创建数据库'。你提出的是他绑定数据,并立即绑定重新保存到数据库。 – 2012-02-21 11:43:12

+0

使用上面的代码,当你想存储数据,而数据绑定到中继器。否则使用Daniel McNulty战略 – 2012-02-21 11:43:15

+0

雅。你是正确的丹尼尔 – 2012-02-21 11:44:00

相关问题