How can I execute an insert with data from a repeater-generated form whose data source is SQL?

Posted by Duke on Stack Overflow See other posts from Stack Overflow or by Duke
Published on 2010-03-18T17:16:57Z Indexed on 2010/03/18 17:21 UTC
Read the original article Hit count: 229

Filed under:
|
|
|
|

I'm storing multilingual data in a database whose model is language normalized (like this).

For this particular problem the key for the table in question consists of a value entered by the user and a language from the language table. I'd like to dynamically generate a form with input fields for all available languages.

The user inputs a key value then goes down a list of field sets filling out the information in each language. In this case there are two fields for every language, a name and a value (the value is language dependent.)

I have all existing information displayed on the page with a gridview, below which I have a formview that is always in insert mode allowing the user to enter new data. Within the formview I have a repeater with an SQLDataSource that gets a list of available languages:

<asp:Repeater ID="SessionLocaleRepeater" runat="server"
    DataSourceID="LocaleSQLDataSource"
    EnableViewState="false">
    <ItemTemplate>
    <tr>
      <th scope="row"><%# DataBinder.Eval(Container.DataItem, "LocaleName") %></th>
      <td>Name:</td>
      <td><asp:TextBox ID="TextBox1" runat="server" Text="" /></td>
      <td>Number:</td>
      <td><asp:TextBox ID="TextBox2" runat="server" Text="" /></td>
    </tr>
    </ItemTemplate>
</asp:Repeater>

I figured that in order to insert this data I'd have to execute my sql server insert stored procedure for each item in the repeater; I am trying to use the formview inserting event. The problem is that the repeater isn't databound to the SQLDataSource until after the formview inserting event (inserting event is in PostBackEvent and databind is in PreRender), which means the controls and data are not available when the inserting event is fired.

I tried databinding the repeater during the formview inserting event; the controls were available but the data was not. Would this have something to do with how/when the viewstate information is re-added to the controls? From what I've read, Viewstate is one of the first things to be restored.

Given the order of events how can I get the data I need for the insert?

I'm open to other solutions to creating dynamic input controls, but they will have to query the database to determine how many sets of controls to create.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about dynamic