0
我已經使用更新面板,並在更新面板我一直在我動態又包含1名下拉列表和3個文本框創建行ASP表控制丟失。我的問題是,發現部分回發文本框和下拉列表後,但文本框的文本屬性顯示爲空,下拉列表的選定值設置爲該框中的第一條記錄。我還在會話中存儲了整個表,並在page_load事件的(!isPostBack)條件中檢索它。請指導我如何解決這個問題?我的.aspx頁面中的數據後部分回發
部分如下
<td colspan="2">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" EnableViewState="true">
<ContentTemplate>
<table class="style1">
<tr>
<td>
<table class="style1" border="1">
<tr>
<td width="120">
<asp:Label ID="QualificationLbl" runat="server" Text="Qualification"></asp:Label> </td>
<td width="100">
<asp:Label ID="PercentageLbl" runat="server" Text="Percentage"></asp:Label>
</td>
<td width="100">
<asp:Label ID="YearLbl" runat="server" Text="Passing Year"></asp:Label>
</td>
<td width="*">
<asp:Label ID="InstituteLbl" runat="server" Text="Institute Name" Width="120px"
onprerender="InstituteLbl_PreRender"></asp:Label>
</td>
</tr>
<tr>
<td colspan="4" align="left">
<asp:PlaceHolder ID="PlaceHolder" runat="server"></asp:PlaceHolder>
<asp:Table ID="Table1" runat="server">
</asp:Table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right">
<asp:Button ID="addRowBtn" runat="server" onclick="addRowBtn_Click"
Text="Add New Row" />
</td>
</tr>
</table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="addRowBtn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<br />
</td>
和我.aspx.cs頁面如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using AppResumeMaster;
using AppQualificationDetail;
public partial class Applicant_ApplicationForm : System.Web.UI.Page
{
int Rows = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
generateTable(Rows);
}
else
{
Table ReturnedTable = new Table();
ReturnedTable = (Table)Session["Table"];
int rowCount = ReturnedTable.Rows.Count;
int colCount = 4;
DropDownList objList = new DropDownList();
TextBox txtBox = new TextBox();
if (ReturnedTable != null)
{
for (int Rcount = 0; Rcount < rowCount; Rcount++)
{
for (int Ccount = 0; Ccount < colCount; Ccount++)
{
if (Ccount == 0)
{
objList = (DropDownList)ReturnedTable.Rows[Rcount].Cells[Ccount].FindControl("DropDownList(" + Rcount + "," + Ccount + ")");
objList.SelectedValue = ((DropDownList)ReturnedTable.Rows[Rcount].Cells[Ccount].FindControl("DropDownList(" + Rcount + "," + Ccount + ")")).SelectedValue;
}
else
{
txtBox = (TextBox)ReturnedTable.Rows[Rcount].Cells[Ccount].FindControl("TextBox(" + Rcount + "," + Ccount + ")");
txtBox.Text = ((TextBox)ReturnedTable.Rows[Rcount].Cells[Ccount].FindControl("TextBox(" + Rcount + "," + Ccount + ")")).Text;
//txtBox.Text = Request.Params["TextBox(" + Rcount + "," + Ccount + ")"];
}
}
}
}
}
}
protected void saveBtn_Click(object sender, EventArgs e)
{
}
protected void addRowBtn_Click(object sender, EventArgs e)
{
if (ViewState["rowCount"] != null)
{
Rows = Convert.ToInt32(ViewState["rowCount"].ToString());
generateTable(Rows);
}
}
public void generateTable(int rowCount)
{
try
{
int colCount = 4;
DropDownList objDropDownList;
for (int Row = 0; Row < rowCount; Row++)
{
TableRow objTablerow = new TableRow();
for (int cols = 0; cols < colCount; cols++)
{
TableCell objTableCell = new TableCell();
if (cols == 0)
{
objDropDownList = new DropDownList();
objDropDownList.Width = 120;
objTableCell.Controls.Add(objDropDownList);
DataOperation objDataoperation = new DataOperation();
DataSet ds = new DataSet();
ds = objDataoperation.DropDownList("select * from tblQualificationMaster");
objDropDownList.DataValueField = ds.Tables[0].Columns[0].ToString();
objDropDownList.DataTextField = ds.Tables[0].Columns[1].ToString();
objDropDownList.DataSource = ds.Tables[0];
objDropDownList.DataBind();
objDropDownList.ID = "DropDownList(" + Row + "," + cols + ")";
objTableCell.Controls.Add(objDropDownList);
objTablerow.Controls.Add(objTableCell);
}
else
{
TextBox objTextBox = new TextBox();
objTextBox.ID = "TextBox(" + Row + "," + cols + ")";
objTableCell.Controls.Add(objTextBox);
objTablerow.Controls.Add(objTableCell);
}
}
Table1.Rows.Add(objTablerow);
}
rowCount++;
ViewState["rowCount"] = rowCount;
}
catch (Exception ex)
{
throw ex;
}
}
protected void InstituteLbl_PreRender(object sender, EventArgs e)
{
Session.Add("Table", Table1);
}
}
我想通過對每一個addRowTbn點擊事件中添加一行有保留以前的行。
感謝扎克您的回覆,但我不明白你想說什麼。請指導我如何解決這個問題... – 2011-03-21 04:19:52