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>
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>