2
html 테이블이 visibile인지 여부에 따라 루프를 반복하고 각 루프마다 다른 매개 변수 값을 할당 할 수 있습니까? 이것은 이것이 올바른 접근 방법인지 확실하지 않지만 가능한 경우 다음을 수행하는 방법에 대한 조언과 몇 가지 샘플 코드를 원합니다.루프를 기반으로 매개 변수 값 변경
표 예를
Four of these tables so for the second table I have the id="txtLName1"
<table id="tblEvent1" class="tblAttendee">
<tr>
<td>Last Name:</td>
<td><input id="txtLName" runat="server" type="text" name="name" /></td>
</tr>
<tr>
<td>First Name:</td>
<td><input id="txtFName" runat="server" type="text" name="name" /></td>
</tr>
<tr>
<td>Gender:</td>
<td><asp:DropDownList ID="ddlGender" runat="server" Width="65%">
</asp:DropDownList></td>
</tr>
<tr>
<td>Age:</td>
<td><asp:DropDownList ID="ddlAge" runat="server" Width="65%">
</asp:DropDownList></td>
</tr>
<tr>
<td>Comments:</td>
<td><textarea id="txtComments" runat="server" type="text"></textarea></td>
</tr>
</table>
Table1 - visible = true
Table2 - visible = true
Table3 - visible = true
Table4 - visible = false
using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "StoredProcedureName";
cmd.CommandType = CommandType.StoredProcedure;
Loop through tables where visible = true
//first loop
cmd.Parameters.AddWithValue("@LastName", Request.Form["(Table1.LastName"]);
insert new record to database
//second loop
cmd.Parameters.AddWithValue("@LastName", Request.Form["Table2.LastName"]);
insert new record to database using same storedprocedure call
//third loop
cmd.Parameters.AddWithValue("@LastName", Request.Form["Table3.LastName"]);
insert new record to database using same storedprocedure call
No 4th loop because Table is not visible.
결국 데이터베이스 테이블이 경우 3 개 레코드를 삽입하기 위해이 같은 저장 프로 시저를 사용하지만, 그래서 호출됩니다 여러 번 반복이 같은 뭔가를해야
(LastName)Smith (firstName)Bob (gender)Male (age)13 (linkid)1
(LastName)Smith (firstName)Timmy (gender)Male (age)7 (linkid)1
(LastName)Smith (firstName)Jenny (gender)Female (age)9 (linkid)1
웹 양식 또는 mvc를 사용하고 있습니까? 페이지의 코드는 어떻게 생겼습니까? 표가 어떻게 채워지나요? – TomT
테이블 TomT의 예가 webforms asp.net C#이고 SQL 테이블이 나열된 필드를 기반으로 채워집니다. 어쩌면 나는 충분히 명확하게 질문하지 않았지만 데이터베이스에 첫 번째 테이블을 삽입 한 다음 루프가 두 번째 테이블을 새 레코드로 삽입하는 등 내 웹 페이지 루프에 표시되는 테이블의 수에 따라 노력하고 있습니다. – Tim