EditCommandColumn and Data Grid Help

  • Thread starter srini.venkatesan
  • Start date
S

srini.venkatesan

Please see the class file and the asp file. I want to validate two text
fields when the update is clicked. As you guys know, when the edit is
clicked, it changes to update and cancel.
I want to validate on update click by a javascript. If anyone can tell
me, how to pass the
values to the javascript that will be great. This is done VS2003.

Part of the class file

public void DataGrid2_Edit(Object sender, DataGridCommandEventArgs e)
{


TableCell cell = (TableCell) e.Item.Controls[0];
System.Web.UI.WebControls.LinkButton img =
(System.Web.UI.WebControls.LinkButton ) cell.Controls[0];


img.Attributes.Add("onclick",
"javascript:confirm_update();");
DataGrid2.EditItemIndex = (int)e.Item.ItemIndex;
BindGrid();

}


public void DataGrid2_Cancel(Object sender, DataGridCommandEventArgs
e)
{
DataGrid2.EditItemIndex = -1;
BindGrid();
}

public void DataGrid2_Update(Object sender, DataGridCommandEventArgs
e)
{


string col1text = e.Item.Cells[1].Text;
string col2text = ((System.Web.UI.WebControls.TextBox)
e.Item.Cells[2].Controls[0]).Text;
string col3text = ((System.Web.UI.WebControls.TextBox)
e.Item.Cells[3].Controls[0]).Text;

}




ASP PAGE:

</style>
<script language="javascript">

function confirm_update()
{

//alert("test" + x);
alert("hello" + x);
}
</script>
</HEAD>
<BODY>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid2" runat="server"
AutoGenerateColumns="false" OnUpdateCommand="DataGrid2_Update"
OnCancelCommand="DataGrid2_Cancel" OnEditCommand="DataGrid2_Edit"
HeaderStyle-BackColor="#aaaadd"
Font-Size="8pt" Font-Name="Verdana" CellPadding="3" BorderWidth="1"
BorderColor="black"
onselectedindexchanged="DataGrid2_SelectedIndexChanged">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:BoundColumn HeaderText="COL1" DataField="col1text"
ReadOnly="True" />
<asp:BoundColumn HeaderText="COL2 DataField="col2text" />
<asp:BoundColumn HeaderText="COL3" DataField="col3text" />
</Columns>
</asp:datagrid>
</form>
</BODY>
</HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top