Click here to Skip to main content
15,868,419 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Please enlight me how to insert/update/delete records based on generated textbox/checkbox.

I used the following code to generate the textbox/checkbox:

ASP.NET
<asp:Repeater ID="myRepeater" runat="server" >
                  <HeaderTemplate>
                      <table >
                          <thead><tr>
                                    <th>Terminal Tab</th>
                        <th>Terminal Attributes</th>
                        <th>Values
                               </th></tr></thead>
                          <tbody>
                  </HeaderTemplate>
                  <ItemTemplate>
                  <tr>
                 <td><%# Eval("TabName") %></td>
                     <td><%# Eval("TagName") %></td>
                 <td><%# GenerateTag(Eval("Datatype"))%></td>
                  </tr>
                  </ItemTemplate>
                  <FooterTemplate>
                      </tbody>
                      </table>
                  </FooterTemplate>
              </asp:Repeater>

Below is the function of GenerateTag:
C#
/// <summary>
/// Generate tages based on data type.
/// </summary>
/// <param name="objDataType"></param>

protected string GenerateTag(object objDataType)
{
    String strTags = "";

    switch (objDataType.ToString()) {
        case "Char":
            strTags = "<input id=tagText type=text  />";
            break;
        case "Int":
            strTags = "<input id=tagInt type=text  />";
            break;
        case "Boolean":
            strTags = "<input id=cbx type=checkbox  />";
            break;
        default:
            strTags = "<input id=strInput type=text />";
            break;
    }
    return strTags;
}


I use the following SQL statement in myRepeater:

C#
string strSQL = @"
        Select       T.ID
                   , T.TabID  TabID
                   , Tab.Name TabName
                   , T.TagName
                   , T.AppID
                   , T.DataType
                   , T.MinLen
                   , T.MaxLen
                   , A.Name AppName
                   , T.Description
        From TerminalAttrTag T
              Left Join TerminalAttrApp A   on T.AppID = A.ID
              Left Join TerminalAttrTab Tab on T.TabID = Tab.ID
                    Where T.AppID = {0} or T.AppID = 1
                    Order by T.TabID, T.SeqNo
        ";

 strSQL = String.Format(strSQL, AppID);

 myRepeater.DataSource = bl.GetDataSet(ConnectionString, strSQL);
 myRepeater.DataBind();



In screen, it shows:

XML
Terminal Tab                Terminal Attributes         Values

Host Config                 Host Name                  (Textbox)
Host Config                 Host IP                    (Textbox)
Host Config                 Timeout                    (Textbox)


I can input below info:

Terminal Tab                Terminal Attributes         Values

Host Config                 Host Name                  Machine1
Host Config                 Host IP                    10.1.1.2
Host Config                 Timeout                    30


Now I want to be able to click "Add" button to input below record (2nd records).


XML
Terminal Tab                Terminal Attributes         Values

Host Config                 Host Name                  Machine2
Host Config                 Host IP                    10.2.2.2
Host Config                 Timeout                    50



I am thinking to use DetailsView but in the end I give up due to the dynamic generated textbox.

1. Please enlight me how I can add code in 'Add' button to insert records. Or which part of code need to be fixed or rewrite? And please advise the suitable way to handle this.

2. After problem of add/delete/update records solved, please enlight me how to loop through the records. I need to save all records to database or xml files.

Thank you for your patient.
Posted
Updated 3-Jan-13 9:44am
v4

1 solution

Sorry for not answering the question, but one caught fragment made a really strong pain in my eyes. I mean switch statement with objDataType.ToString().

I cannot stand it. How anyone can write such things? First of all, this is a really fatal trend to work with string representation of data instead of data itself. And also, two completely different types can return the same string by ToString(). In the very worst case, all you need is this:
C#
protected string GenerateTag(System.Type objectType) { // not object!
    if (objectType == typeof(System.Boolean))
        return // ...
    // ...
    else
        return //...
    // I wanted to write what to return, but noticed that you also violate HTML syntax. You should not omit ""!
}

Don't want to continue as I'm not sure that your whole idea is right...

I want to say: "and so on..." :-)

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900