Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Grid

Status
Not open for further replies.

asraj16

Programmer
May 15, 2004
19
US
Hi,
I want to disable a field in a Data Grid. When I click an edit button in a Data Grid, I need to disable a field in that corresponding row. How to do that?
 
Can't you just make the field Read Only?

Hope everyone is having a great day!

Thanks - Jennifer
 
I can do that. But when I click update button I need to enable this fields and disable other fields.

Click on Edit : disable some fields

Click on Update : enable those disabled fields, and disable other fields.

In the same events, Calling the same page.

How to do that?
 
I am not sure but I would investigate the ItemDataBound event. The following is one that I use to change a LinkButton based on the selected row. Hopefully this will point you in the right direction.

public void dg_ItemDataBound(Object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {
if (e.Item.ItemType != ListItemType.Header & e.Item.ItemType != ListItemType.Footer) {
LinkButton lnkBtn = (LinkButton)e.Item.Cells[0].Controls[1];

string strItem = Convert.ToString(dg.DataKeys[e.Item.ItemIndex]);

lnkBtn.Font.Size = FontUnit.Parse(Convert.ToString((intUnit + Convert.ToInt32(lnkBtn.Font.Size.Unit.Value-10))+"px"));

if (strItem == Convert.ToString(sb.getCurrentValue("Selected_IN",strUser))) {
lnkBtn.ForeColor = colorTextBack;
lnkBtn.BackColor = colorMain;
}
else {
lnkBtn.ForeColor = colorMain;
}
}
}

Hope everyone is having a great day!

Thanks - Jennifer
 
I am using the following Code.

When I click on Edit, I need to Disable a DataField.

<asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False" DataKeyField="MSG_RULE_ID" OnItemCommand="DataGrid_ItemCommand" OnEditCommand="DataGrid_Edit" OnUpdateCommand="DataGrid_Update" OnCancelCommand="DataGrid_Cancel" OnDeleteCommand="DataGrid_Delete" AllowPaging="True" PageSize="12" OnPageIndexChanged="DataGrid_Page" ForeColor="Black" BackColor="White" CellPadding="3" GridLines="None" CellSpacing="1" width="80%">
<FooterStyle backcolor="#C6C3C6"></FooterStyle>
<HeaderStyle font-bold="True" forecolor="White" backcolor="#4A3C8C"></HeaderStyle>
<PagerStyle font-size="Smaller" horizontalalign="Right" backcolor="#C6C3C6" mode="NumericPages"></PagerStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit">
<ItemStyle font-size="Smaller" width="10%"></ItemStyle>
</asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete">
<ItemStyle font-size="Smaller" width="10%"></ItemStyle>
</asp:ButtonColumn>
<asp:BoundColumn Visible="False" DataField="MSG_RULE_ID"></asp:BoundColumn>
<asp:BoundColumn DataField="DISTRIBUTION_TP_CD" HeaderText="Distribution Type"></asp:BoundColumn>
<asp:BoundColumn DataField="DISTRIBUTION_DESC" HeaderText="Distribution Value"></asp:BoundColumn>
<asp:BoundColumn DataField="EFFECTIVE_START_DT" HeaderText="Effective Start Date"></asp:BoundColumn>
<asp:BoundColumn DataField="EFFECTIVE_END_DT" HeaderText="Effective End Date"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATE_TS" HeaderText="Added Date"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATE_USER_ID" HeaderText="Added by"></asp:BoundColumn>
<asp:BoundColumn DataField="LAST_MODIFY_TS" HeaderText="Modified Date"></asp:BoundColumn>
<asp:BoundColumn DataField="LAST_MODIFY_USER_ID" ReadOnly="True" HeaderText="Modified By"></asp:BoundColumn>
<asp:BoundColumn DataField="MSG_TEXT1" HeaderText="Message Text Line 1"></asp:BoundColumn>
<asp:BoundColumn DataField="MSG_TEXT2" HeaderText="Mesage Text Line 2"></asp:BoundColumn>
<asp:BoundColumn DataField="MSG_TEXT3" HeaderText="Message Text Line 3"></asp:BoundColumn>
</Columns>
</asp:datagrid>
 
The code is the HTML what about the code behind?

Hope everyone is having a great day!

Thanks - Jennifer
 
First step to disable DG record...
this would be the onEditCommand event...
Code:
    Sub DataGrid_Edit(Sender As Object, E As DataGridCommandEventArgs)
        If Not isEditing Then
            DataGrid1.EditItemIndex = e.Item.ItemIndex
            BindGrid()
            [b]DataGrid1.Items(DataGrid1.EditItemIndex).Cells(3).enabled = false[/b]
        End If
    End Sub

i noticed that you cannot perform the update when disabled though... so...i will see what i can do on reenabling on the update command.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top