Avatar of ajay1feb
ajay1feb asked on

how can show alert for every row record in data table?

i have one datatable .for each row of datatable i want to show only one alert.suppose first rwo has value "mango" second row has value "orange" and third has value "apple".then how i can show alert in following format.

these are good fruits

mango
orange
apple
JavaScriptC#

Avatar of undefined
Last Comment
ajay1feb

8/22/2022 - Mon
msram78

it would be easy if you are more precise.  in this case you can loop through the datatable in the javascript,  store the value of each row in a variable and display the alert with the variable at the end of the loop.
ASKER
ajay1feb

i am doing like following but it is showing alert only last record.not for all row.

 if (dtGridItems!=null )
                 {

                     foreach (DataRow dr in dtGridItems.Rows)
                     {
                         productLine = dr["ProductLine"].ToString() ;
                         productType = dr["ProductType"].ToString() ;
                         catalogNo = dr["CatalogNumber"].ToString() ;                        

                         string strBtnChange = string.Empty;
                         strBtnChange = "<script language='JavaScript'> alert('Product Line " + productLine.Trim() + " Product Type " + productType.Trim() + " Catalog Number " + catalogNo.Trim() + " combination already exists '); </script>";
                         ClientScript.RegisterStartupScript(this.GetType(), "strSavedData", strBtnChange);


                     }
                   
                 }

msram78

my code is javascript.  put my code in a javascript function.  and call that function and click of a button that is outside the datagrid.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
ajay1feb

i didn't get ur code.where it is ?
msram78

sorry i missed that.

var rowposi = document.getElementById('<datagrid/table name>').rows;
var strvar = ""
for (var i=0;i<document.getElementById('<datagrid/table name>').rows.length;i++)
{
      var strCtrl2 = rowposi[i].childNodes[0].innerHTML; // this will get the html content of a column in the grid
      var strtextid = ""
      strtextid = strCtrl2.substring(strCtrl2.indexOf('id=') + 3, strCtrl2.indexOf(' ', strCtrl2.indexOf('id='))) // this will give the name of the control as in the html
              strvar = strvar + document.getElementById(strtextid ).value
}
alert (strvar)
ASKER
ajay1feb

in my datatable i have three column.try to see my code which i have sent you.for each row i need to display only one alert.kindly try to give me code in my context.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Murtie


Create a string var outside the loop

 Assign String to the first row item
String = Row.Item(0)
global VAR String


LOOP
For each row in datatable

if NOT String = row.Item(x)

MessageBox.Show(Row.Item(x))

String = row.Item(x)
End if



Next

END LOOP

Each time the loop runs it will check if it has shown this string before, if it ihas then it will ignore it otherwise it will show the string.

Hope this psuedo code helps a lil.
ASKER CERTIFIED SOLUTION
msram78

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
ajay1feb

on every row it should first add message in alert.if there is three row in table then three alert message  should attached row by row in alert message.how to do it?i dont want three times alert.i want only one time alert for all three rows in datatable.
ASKER
ajay1feb

dear msram78,

   your code is near about right.but somewhere error in code and i need new line option also in alert message for displaying all alert message line by line.pls help out we are very near to solve it.

Regards,
ajay
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
msram78

see the code i wrote on the fly in this.  i didnt test it.  its just the logic.  what error r u getting ?  to add new line character put  + "\n"; at the end of the line

strFinal = strFinal + "Product Line :" + productLine.Trim() + " Product Type :" + productType.Trim() + " Catalog Number " + catalogNo.Trim() + " combination already exists" + "\n";
ASKER
ajay1feb

unterminated string constant.

above error is giving after adding + "\n";
my code is following:if i remove + "\n"; from my following code.it is working fine.but next message is not coming in next line.it is coming in same line.so now only problem is next line issue.
 

 if (dtGridItems != null)
                {
                    string strFinal = "";
                    foreach (DataRow dr in dtGridItems.Rows)
                    {
                        productLine = dr["ProductLine"].ToString();
                        productType = dr["ProductType"].ToString();
                        catalogNo = dr["CatalogNumber"].ToString();
                        strFinal = strFinal + "Product Line :" + productLine.Trim() + " Product Type :" + productType.Trim() + " Catalog Number " + catalogNo.Trim() + " combination already exists" + "\n";

                    }
                    string strBtnChange = string.Empty;
                    strBtnChange = "<script language='JavaScript'> alert('" + strFinal + "'); </script>";
                    ClientScript.RegisterStartupScript(this.GetType(), "strSavedData", strBtnChange);

                }
msram78

try "\\n" instead of "\n"
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
ajay1feb

superb.great help.where do u work?