How to make the DetailsView's edit button visible according to the state of one field of a GridView's selected row?

Hello everyone!

Now I am working with a Master/Detail page that using a gridview and a detailsview.

The detailsview is set to editable and the edit button is autogenerated.

I want to make the DetailsView's edit button visible according to the state of one field of a GridView's selected row.

I tried to access the selected row of the gridview in the detailsview's ItemCreated event or DataBound event,using the following code

GridViewRow row = gvwMaster.SelectedRow

But it goes wrong with this line of code.

And then I tried to write some code in the gridview's SelectedIndexChanged event handler,something like this:

           GridViewRow row = gvwMaster.SelectedRow;
            if (row.RowType == DataControlRowType.DataRow)
            {

                if ((row.Cells[4].FindControl("lblState") as Label).Text != "SomeText")
                {
                    dvwDetails.AutoGenerateEditButton = false;
                }
            }

But still it doesn't work.

Can someone tell me how to deal with this problem?

Thank you very much!

0
SSnake
4/16/2007 11:20:44 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
1051 Views

Similar Articles

[PageSpeed] 33

I got it to work in the DetailsView's PreRender event

    protected void DetailsView1_PreRender1(object sender, EventArgs e)
    {
        DetailsView1.AutoGenerateEditButton = CheckBox1.Checked;
    }
 But, I ended up with two rows of commands.  If you do it this way, you'll have to put "Delete" and "Insert" in the code also.
Steve Wellens

My blog
0
SGWellens
4/17/2007 1:59:42 AM
SGWellens:

I got it to work in the DetailsView's PreRender event

    protected void DetailsView1_PreRender1(object sender, EventArgs e)
    {
        DetailsView1.AutoGenerateEditButton = CheckBox1.Checked;
    }

 But, I ended up with two rows of commands.  If you do it this way, you'll have to put "Delete" and "Insert" in the code also.

to SGWellens

Thank you for your help.

But this method does not work for the DetailsView.

At last,I change the DetailsView to the FormView ,and in the FormView's PreRender event handler,I write the same code

And this time,it finallly work.

Thank you very much!

0
SSnake
4/17/2007 4:35:34 AM
Reply:

Similar Artilces:

how to control a RadioButtonList's Listitem's text show according database's field
Hi my page has a repeater control,in repeater has a RadioButtonList control now i want to let the RadioButtonList has four Listitem,every Listitem's text is a database's field so the listitem can show dynamic according every record how can i work out my problem thanks a lot  hello dearbound your RadioButtonList to database if i m not clear fell free 4 replySatyabrat SinghB.E.(C.Sc.)Web developer Livetek Solution Dont forget to click "Mark as Answer" on the post that helped you. yes.i bound the radiobuttonlist to a dataset but how to display the ...

First gridview's selected row doesn't update second gridview's objectdatasource
 HelloI got 2 gridviews on a page, each with its own ObjectDataSource. The first gridview fills itself just normally, no problem there. The second gridview needs to fill itself with other data, where the primary key is the primary key of the selected row of the first gridview.schematically:gridview1 row: IDfield, x, y, zrow: IDfield, x, y, z (-> this row is selected)row: IDfield, x, y, z gridview2 row:IDfield_of_selected_row_in_gridview1, a, b, c I tried to do this by configuring the ObjectDataSource behind gridview2 with a parameter pointing to gridview1.selectedValue. (by usin...

Replace 1's and 0's in a gridview column with Yes's and No's
Is it possible to change the display of a column in a gridview to show a Yes for all 1's and a No for 0's that display in a particular column of a gridview bound to a database?  If so, can someone share the way with me?  I am using ASP.NET 2.0 with VB Code Behind.  Thanks One way you can do is thrrough  CASE in your select statement: Select YesNoColumn= CASE yourColumn WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' ELSE '' END FROM YourtableLimno <Columns>     <asp:TemplateField HeaderText="yourHeader" SortExpression="yourDataField"> ...

How To Get the Gridview's Field Value if the Column's Visible=False..?
Here is the scenario: My sql query returns Name, ID, SSNum. I use a gridview which has 3 columns Name, ID and SSNum (with SSNum is set visible=false) so the gridview only shows Name and ID. I need to use part of SSNum to form a NewUserID in the code behind. Im doing this by using the gvResult_OnRowDataBound. So far, if I set SSNum column's visible=false then I wont see this field on row data bound. Any suggestion as how to obtain this SSNum from the code behind?  you can set it as the datakey on the properties of the grid view and use this codethis.GridView1.DataKeys[this.Gri...

how to let ButtonColumn control button's visible's property in DataGrid
Hi I has a ButtonColumn in a DataGrid,and a button in the page, In the page_load() event i wrote: if (Not IsPostBack) then   button1.visible=false end if and the ButtonColumn CommandName="delete" in the DataGrid1_delete() event i wrote   button1.visible=true But when i press the "delete" ButtonColumn ,the button1 can not be visible,i don;t why How can when i press "delete" ButtonColumn,the Button1 can be visible Thanks a lot.       yugiant:How can when i press "delete" ButtonColumn,the Button1 can be visibl...

How would I make a custom control's button's onclick event public?
I'd like to do something programatically in the parent class once a custom control's button is clicked.Anyone has a link to a tutorial?  http://msdn2.microsoft.com/en-us/library/aa645739(VS.71).aspxThanks, EdMicrosoft MVP - ASP/ASP.NET thanks but I'm looking for a tutorial for asp.net since I'm not too sure how the intricacies of asp.net change or simplify that example  http://www.odetocode.com/Articles/94.aspxThanks, EdMicrosoft MVP - ASP/ASP.NET thanks a lotI feel mildly dumb now  ...

Setting a panel control's visibility and it's affect in nested controls.
I am trying to debug a page using the panel control.  The code in the final submission of the form has logic to get data from a dropdown based on the control's visibility.  If the control's visibility is set to true, the the data is retrieved and sent to the database.The problem appears to be the dropdown control's visibility is set to false when it should not.  The dropdown is nested in a panel control.  While doing a trace, it appears when a panel control's visibility is set to false, the visibility for all controls nested under this panel are set to false as well.You'r...

How to change the 'edit' button to 'Update'+'Cancel' button in Gridview
Hi all, I'm using a commandField 'edit' button in a Gridview which I hope to be changed to a 'update' and a 'cancel' button when the 'edit' button is pushed. My codes are as follow.  My problem is that I don't know what codes should be added to make the change I mentioned to happen. THanks a lot for your assistance. TOny<%@ Page Language="VB" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><%@ Import Namespace="syste...

It's Linux !? No, it's BSD ! No, no, it's...
kFreeBSD http://wiki.debian.org/Debian_GNU/kFreeBSD a Debian distro using the FreeBSD kernel ! ObiWan wrote: > kFreeBSD > > http://wiki.debian.org/Debian_GNU/kFreeBSD > > a Debian distro using the FreeBSD kernel ! Why use a BSD kernel? I hope the reason is more than, just because they can. http://wiki.debian.org/Debian_GNU/kFreeBSD_why It's easy to understand why the would want to use Debian packages. :) -- Jimmy Johnson Registered Linux User #380263 >> kFreeBSD >> >> http://wiki.debian.org/Debian_GNU/kFreeBSD >> ...

changes made from one user's webpart's page, effects all user's
 I am just doing this offline right now in Visual Web Developer Express 2008I created the login inonce in the memberpage area, people can modify their webpart page. I created several users to test this out.  I loaded it in a browser.When I make changes as logged in user "A" .  Then logout and login as user "B", user "B,s" webpart page has been changed to user "A".This goes true for whomever I log in as.  It changes for everyone.Is there something specific I need to do in order to get everyone's changes to be unique for them...

GridView doesn't refresh it's schema after the object data source's GetData() method returns additional fields .
Hi . I am creating an ASP.NET web site and have the following problem :  I have a GridView which bound to the object data source. This object data source is SQL Table adapter that I added to the data set via IDE . The method GetData of this table adapter uses existing stored procedure on my SQL 2005 server. Everything worked fine , until I made a changes to the stored procedure ( the new result records have additional fields )  .  The problem is :   The new fields don’t appear in the grid . Note : When I right click to the GetData method inside the tabl...

'Tab' control 's visible doesn't work.Why?
I use tab control in my applition. And I set visible=false, but it doesn't work. my code is: ----------------------------------------------- <asp:ScriptManager ID="ScriptManager1" runat="server" />  <div>   <ajaxToolkit:TabContainer runat="server" ID="Tabs" Height="138px" ActiveTabIndex="0"    Width="402px">    <ajaxToolkit:TabPanel runat="server" ID="Panel1" HeaderText="Tab1" Visible="f...

Help! I cannot access the DataGrid's ItemTemplate's LinkButton's Text Atrribute 's Value!!!!!!!!!!!
I write a datagrid's ItemDataBound method as follows:   private void dgTable_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)  {   if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)   {    if(!isRole("Manager"))    {     LinkButton tmp = (LinkButton)e.Item.FindControl("lbPassed");     if(tmp.Text == "Passed")     {      ((LinkBu...

Hyperlink's, ImageURL's, and OnError's
I created an ASP:Hyperlink and set the ImageURL attribute so the link will be the image.If the image is missing, I would like it to display a 'missing image' pic that I have.  I know you can use the OnError attribute of the <img> tag to run some javascript to change it.Unfortunately I can't find a way to access the Hyperlink's Image that is inside it, so I can add an Attribute so the resulting <img> tag will have an OnError attribute inside of it.Any help?If my Hyperlink is called 'foo'....would I do...  ((Image) foo.Controls[0]).Attributes.Add(&...

Web resources about - How to make the DetailsView's edit button visible according to the state of one field of a GridView's selected row? - asp.net.presentation-controls

Resources last updated: 1/5/2016 8:16:22 AM