私はASP.NETで新しいです。私はGridViewを使用します。 GridViewの行数をカウントすると、常に0が表示されます。私はコードを与えている。しかし、コードブラウザを実行すると、データが表示されます。どのようにこの問題を解決する?GridView.Row.Count常に0、どのように解決するには?
私のCSコードは次のとおりです。
protected void btnSend_OnClick(object sender, EventArgs e)
{
string MemberList= (ViewState["Memberlist"]).ToString();
List<PreparedEmail> preparedEmail = new List<PreparedEmail>();
Utility util = new Utility();
int count = 0;
int i1 = dlClients.Rows.Count; // it shows always 0
#region Send Invitation
foreach (GridViewRow mail in dlClients.Rows)
{
//some code here, It is never execute as dlClients.Rows shows 0
}
}
私のaspxコードは次のとおりです。
<asp:GridView ID="dlClients" EnableViewState="false" runat="server" AutoGenerateColumns="False" ClientIDMode="Static" GridLines="None" AllowPaging="false" CssClass="table table-bordered table-striped" OnPreRender="dlClients_PreRender" DataKeyNames="MemberId" PageSize="10" ShowHeader="true">
そして、私のデータバインディングコード:button_click
イベントがあなたのprerender
イベントの前に
Protected void dlClients_PreRender(object sender, EventArgs e)
{
List<CircleUser> memberList = new CircleUserBusinessLogic().GetAll();
dlClients.DataSource = memberList;
dlClients.DataBind();
//GridUpdatePanel.Update();
ViewState["Memberlist"] = memberList;
if (dlClients.Rows.Count > 0)
{
//Replace the <td> with <th> and adds the scope attribute
dlClients.UseAccessibleHeader = true;
//Adds the <thead> and <tbody> elements required for DataTables to work
dlClients.HeaderRow.TableSection = TableRowSection.TableHeader;
//Adds the <tfoot> element required for DataTables to work
dlClients.FooterRow.TableSection = TableRowSection.TableFooter;
}
}
にあなたに1つのページからデータを渡す方法で、あなたのASPXに= "true" をautogeneratedcolumnsを設定しましたか? autogeratecolumnsをtrueに設定した場合は、常にゼロになることを意味します。 –
私のaspxコード: ...どうすればいいですか? –
user2488166