我已經在網格視圖中填充數據。此外,我還使用行數據綁定中的代碼編寫了將圖像URL更改爲圖像的代碼。如何在回發時保留gridview數據?
下面是代碼:
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
for (int i = 1; i < e.Row.Cells.Count; i++)
{
string cellValue = e.Row.Cells[i].Text.Trim();
if(cellValue.StartsWith("http:"))
{
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl = e.Row.Cells[i].Text.Trim();
HyperLink hb = new HyperLink();
hb.Controls.Add(img);
e.Row.Cells[i].Controls.Add(hb);
}
}
}
這是工作的罰款。該頁面還有兩個下拉控件。如果我選擇一個下拉控件,我發回。那時候,我已經寫過的圖像變成了URL而不是Image。
你能幫我處理嗎?
在此先感謝。
這裏是我的問題的代碼(我無法張貼整個代碼)
ASPX代碼:
<html>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList2" CssClass="borderradius" runat="server" Height="20px" Width="190px" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" Font-Size="11px">
</asp:DropDownList>
<asp:Button id="sidesbmt" runat="server" onclick="sidesbmt_click"/>
<asp:GridView ID="GridView1" runat="server" Width="100%" CssClass="mGrid" PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
BorderStyle="None" GridLines="Both">
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
</asp:GridView>
</body>
</html>
代碼隱藏
protected void Page_Load(object sender, EventArgs e)
{
}
protected void sidesbmt_Click(object sender, EventArgs e)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
for (int i = 1; i < e.Row.Cells.Count; i++)
{
string cellValue = e.Row.Cells[i].Text.Trim();
if(cellValue.StartsWith("http:"))
{
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl = e.Row.Cells[i].Text.Trim();
HyperLink hb = new HyperLink();
hb.Controls.Add(img);
e.Row.Cells[i].Controls.Add(hb);
}
}
}
是什麼在你的網頁加載列?如果(!IsPostback){...}在你的頁面加載時添加 – Sam 2014-09-04 11:25:18
我已經在按鈕中寫入數據綁定點擊不在頁面加載..... – Vanarajan 2014-09-04 11:28:04
請將整個代碼aspx和代碼放在後面。 – Priyank 2014-09-04 11:29:26