Hi
I want if value in Gridview column is 'D' or 'S' then SessionDate should be disabled
Go
Thanks
Hi
I want if value in Gridview column is 'D' or 'S' then SessionDate should be disabled
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted May 6, 2023, 1:36 PM EDT
you can also test this
'">Style="text-align: right"Tuhin PaulRank #7 · 71.9K reputationPosted May 6, 2023, 11:08 PM EDT
protected void grdPlanning_RowDataBound(object sender, GridViewRowEventArgs e) { // Check if the current row is a data row if (e.Row.RowType == DataControlRowType.DataRow) { // Find the TextBox control for SessionDate in the current row TextBox txtSessionDate = (TextBox)e.Row.FindControl("txtSessionDate"); // Get the value of the column that you want to check (replace "ColumnName" with the actual name of the column) string columnValue = DataBinder.Eval(e.Row.DataItem, "ColumnName").ToString(); // Check if the value of the column is "D" or "S" (disable the textbox if true) if (columnValue == "D" || columnValue == "S") { txtSessionDate.Enabled = false; } else // if the value of the column is not "D" or "S" (enable the textbox) { txtSessionDate.Enabled = true; } } }Naimish MakwanaRank #324 · 7.7K reputationPosted May 6, 2023, 2:01 AM EDT
You can achieve this by handling the
RowDataBoundevent of the GridView in your code-behind file. In this event, you can check the value of the column and disable the SessionDate TextBox accordingly.Here's some sample code that demonstrates how to do this:
protected void grdPlanning_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { TextBox txtSessionDate = (TextBox)e.Row.FindControl("txtSessionDate"); string columnValue = DataBinder.Eval(e.Row.DataItem, "ColumnName").ToString(); // Replace "ColumnName" with the actual name of your column if (columnValue == "D" || columnValue == "S") { txtSessionDate.Enabled = false; } } }Make sure to replace "ColumnName" with the actual name of the column in your GridView that contains the value you want to check.
Thanks
Anandu G NathRank #681 · 3.5K reputationPosted Dec 27, 2023, 3:26 AM EST