|
|||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionHave you ever faced any problem in Grid view with Drop down list as Item Template and you try to update Grid view records using Object data source But when using Object data source with say Grid view or Form view and trying to update the records which includes a drop down as one template column then comes the problem. 1) Control Parameter 2) Cookie Parameter 3) Form Parameter 4) Parameter 5) Profile Parameter 6) Query String Parameter 7) Session Parameter
If you think of sending through Control Parameter then it’s
not possible. We can use Control parameter with its Id can be set to Grid view
and not the drop down inside Grid view. The solution which one I found is simply adding an update
parameter in code behind. Let me explain how I did all these things. On Grid view’s OnRowCommand Event just added an update parameter for Object data source’s Update Parameter collection. Based on the grid view’s command name is Update Using the Codeprotected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Update")) { int state = 0; int index = int.Parse(e.CommandArgument.ToString()); GridViewRow row = GridView1.Rows[index]; DropDownList lstState = (DropDownList)row.FindControl("StateID"); state = int.Parse(lstState.SelectedValue.ToString()); ObjectDataSource1.UpdateParameters.Add("StateID", state.ToString()); } } 1) Select a Gridview row based on the Gridview selection we will get the row index based on Grid view’s command event argument;s CommandArgument property. 2) Get the drop down list from the selected row through FindControl method on Gridview Row 3) Get the selected value of drop down and add parameter with selected value to Object datasource; s Update Parameters collection. OnrowUpdating Event of Gridview we can call Object datasource;s Update() method to invoke business logic Update method. OnrowUpdating Event of Gridview we can call Object datasource;s Update() method to invoke business logic Update method. protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { ObjectDataSource1.Update(); } Points of InterestPlease don’t try to open Website by just double clicking on solution explorer. Open VS 2005 , File -> Open -> Website and proceed. You will come to know more when you download the code project and run it one's. A project is worth than imagining how it is?
|
||||||||||||||||||||||||||||||||||||||||