开发者

long-winded webpart question

I have a web part, in the createchildcontrols function it creates a gridview, calls a stored procedure and populates the grid view. One column of the gridView is a command field that has the key value for an item & is passed to another web part on the page to show the details. All was working fine until they wanted me to add a search capability to the list web part.

At first this appeared to work, the data in the columns sems to reflect correct search results, but the command field retains the orginal values when the page was first loaded with no search criteria.

Also, when doing the search it appears that it goes through the createchildcontrols function, populates gridview with all of the items, then runs through the code in the btnSearch_Click where more sql is run with the specific search criteria and the gridview is re-bound with the search results (but orginal key values in command field).

Any ideas on how I've messed this up?

Code from CreateChildControls:

_view = new GridView();
this.Controls.Add(this._view);
_view.Caption = "Rate Quote Email";
_view.AutoGenerat开发者_开发技巧eColumns = true;
_view.DataKeyNames = new string[] { "XREF_ID" };
CommandField field = new CommandField();
_view.SelectedRowStyle.BackColor = Color.Red;
field.ShowSelectButton = true;
field.ButtonType = ButtonType.Link;
_view.Columns.Add(field);
_view.AllowPaging = true;
_view.PageSize = 20;
_view.AlternatingRowStyle.BackColor = Color.Cornsilk;
_view.PageIndexChanging += new GridViewPageEventHandler(_view_PageIndexChanging);

Code from btnSearch_Click:

DataSet ds = new DataSet();
rdr = cmd.ExecuteReader();
ds.Clear();
_view.DataSource = null;
ds.Load(rdr, LoadOption.PreserveChanges, "");
rdr.Close();
rdr.Dispose();
_view.DataSource = ds.Tables[0];
_view.DataBind();
DataSet ds = new DataSet();
ds.Clear();
rdr = cmd.ExecuteReader();
ds.Load(rdr, LoadOption.PreserChanges, "");
rdr.Close();
rdr.Dispose();
_view.DataSource = null;
_view.DataSource = ds.Tables[0];
_view.DataBind();
ds.Dispose();
cmd.Dispose();
conn.Dispose();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜