i have a button name save and a datagrid with 2 columns namely drugname which is a combo box and qtyused(simple) and a txtFirstName on the form

if the user enters firstname and 4got to enters or select the datagrid column
i want to remind him/her by a msgbox that she/he has to select the drug name and specify qtyused

a msgbox for the 2 columns drugname and qtyused

help....

Dani AI

Generated

Building on the hints from and for : the reliable approach is to validate the grid on the Save click, not with a server-side MsgBox. MsgBox is a Windows UI call and will not appear in the browser. Server-side logic should walk each DataGrid row, find the drop-down and quantity controls, verify selection and numeric input, then emit a browser alert (or block the save and display validation UI). For partial postbacks use ScriptManager.RegisterStartupScript instead of ClientScript.RegisterStartupScript.

Example server-side pattern (VB.NET) to run in the Save button click:

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
    For Each item As DataGridItem In MyDataGrid.Items
        Dim ddlDrug As DropDownList = CType(item.FindControl("ddlDrug"), DropDownList)
        Dim txtQty As TextBox = CType(item.FindControl("txtQty"), TextBox)
        If ddlDrug Is Nothing Or txtQty Is Nothing Then Continue For

        Dim qty As Integer
        If ddlDrug.SelectedIndex <= 0 OrElse String.IsNullOrEmpty(txtQty.Text.Trim()) OrElse Not Integer.TryParse(txtQty.Text, qty) Then
            Dim msg As String = "Please select a drug and enter a valid quantity for every row."
            ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('" & msg.Replace("'", "\'") & "');", True)
            Return
        End If
    Next

    ' Proceed with saving...
End Sub

Notes: if you prefer client-side feedback for better UX, add JavaScript validation (or validators inside the ItemTemplate). Escape quotes when emitting JavaScript, and validate numeric ranges with Integer.TryParse (server-side) to avoid bad data.

Recommended Answers

All 2 Replies

Hi
I am not clearly understand ur problem. but try this.
Use GotFocus () event of DataGrid and Check the Combo Box whether anything selected or not. If not, show the message box.

I think u need validation in save button click datagrid.row.selected=true then
continue
else
msgbox("Please select Drug name")

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.