sbornstein2
asked on
GridView Button Field, can I enable/disable the button in the column in code behind
I have in my code right now where I can make the column visible or not visible such as:
<asp:ButtonField Text="Publish" ShowHeader="false" HeaderStyle-BackColor="whi te" ButtonType="Button" CommandName="Publish">
<ItemStyle HorizontalAlign="Center" Width="150px" />
<HeaderStyle HorizontalAlign="Center" Width="150px" />
</asp:ButtonField>
this is column 6:
if my condition then:
GridView1.Columns[6].visib le = false;
I want to always show it but make the buttons enabled or disabled?
<asp:ButtonField Text="Publish" ShowHeader="false" HeaderStyle-BackColor="whi
<ItemStyle HorizontalAlign="Center" Width="150px" />
<HeaderStyle HorizontalAlign="Center" Width="150px" />
</asp:ButtonField>
this is column 6:
if my condition then:
GridView1.Columns[6].visib
I want to always show it but make the buttons enabled or disabled?
You need to do this in the RowDataBound event of the GridView
ASKER
can you provide an example at sammy please to handle the enable
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks Sammy really appreciate your help
ASKER
One last question Sammy. Once the button is clicked I do the following in the row command:
if (e.CommandName=="Publish")
{
int index = Convert.ToInt32(e.CommandA rgument);
GridViewRow row = GridView1.Rows[index];
string BookFormatID = row.Cells[1].Text;
for some reason the commandargument is "" and it throws an error. Any idea? I am trying to get the row to get the cell text of column 1.
if (e.CommandName=="Publish")
{
int index = Convert.ToInt32(e.CommandA
GridViewRow row = GridView1.Rows[index];
string BookFormatID = row.Cells[1].Text;
for some reason the commandargument is "" and it throws an error. Any idea? I am trying to get the row to get the cell text of column 1.
ASKER
Input string was not in correct format. I beleive before it would be a number the commandargument
ASKER
Forget it, I figured it out Sammy, thanks again.
CommandArgument="<%# Container.DataItemIndex %>"
CommandArgument="<%# Container.DataItemIndex %>"
Sorry I was too busy today