c# - change the name column text of the current row when the selected index of drop down is changed -


hello followed this link of mudassar , need few it.

how change name column text of current row when selected index of drop down changed?

ex:1st column text 2nd dropdown , when change dropdown want replace text value this

gridview1.rows[currentrowindex.cells[0].text="xyz" 

here aspx file

<form id="form11" runat="server"> <div>     <asp:label id="label1" runat="server" text=" "></asp:label>     <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false" onrowdatabound ="gridview1_rowdatabound">         <columns>             <asp:boundfield datafield="input_metadata_id" headertext="input metadata id" readonly="true" sortexpression="input_metadata_id" visible="false"></asp:boundfield>             <asp:boundfield datafield="input_id" headertext="input id" readonly="true" sortexpression="input_id"></asp:boundfield>             <asp:templatefield headertext = "field">                 <itemtemplate>                     <asp:label id="lblfield" runat="server" text=""/>                     <asp:dropdownlist id="selectfield" runat="server"  appenddatabounditems="true" autopostback="true" onselectedindexchanged="dropdownlist1_selectedindexchanged">                         </asp:dropdownlist>                 </itemtemplate>             </asp:templatefield>             <asp:boundfield datafield="datatype" headertext="datatype" readonly="true" sortexpression="datatype"></asp:boundfield>             <asp:boundfield datafield="size" headertext="size" readonly="true" sortexpression="size"></asp:boundfield>             <asp:boundfield datafield="unit" headertext="unit" readonly="true" sortexpression="unit"></asp:boundfield>         </columns>     </asp:gridview>     <asp:gridview id="gridview2" runat="server" autogeneratecolumns="false" >         <columns>             <asp:boundfield datafield="output_metadata_id" headertext="output metadata id" readonly="true" sortexpression="output_metadata_id"></asp:boundfield>             <asp:boundfield datafield="output_id" headertext="output id" readonly="true" sortexpression="output_id"></asp:boundfield>             <asp:boundfield datafield="field" headertext="field" readonly="true" sortexpression="field"></asp:boundfield>             <asp:boundfield datafield="datatype" headertext="datatype" readonly="true" sortexpression="datatype"></asp:boundfield>             <asp:boundfield datafield="size" headertext="size" readonly="true" sortexpression="size"></asp:boundfield>             <asp:boundfield datafield="unit" headertext="unit" readonly="true" sortexpression="unit"></asp:boundfield>         </columns>     </asp:gridview> </div> </form> 

code behind file

protected void page_load(object sender, eventargs e) { setinputtableinitialrow();         load_output_table(); }   datatable outputtable;  private void load_output_table() {    // int output_id = 2;     string query = "select * output_metadata";// output_id=" + output_id;     outputtable = dataaccess.select(query);     gridview2.datasource = outputtable;     gridview2.databind();     int = 0;  }  private void setinputtableinitialrow()     {         datatable dt = new datatable();          //define columns         dt.columns.add(new datacolumn("input_metadata_id", typeof(int)));         dt.columns.add(new datacolumn("input_id", typeof(int)));         dt.columns.add(new datacolumn("datatype", typeof(string)));         dt.columns.add(new datacolumn("size", typeof(string)));         dt.columns.add(new datacolumn("unit", typeof(string)));         datarow dr = dt.newrow();          dt.rows.add(dr);         gridview1.datasource = dt;         gridview1.databind();      } protected void dropdownlist1_selectedindexchanged(object sender, eventargs e) {     dropdownlist drp = (dropdownlist)sender;     gridviewrow gv = (gridviewrow)drp.namingcontainer;     int index = gv.rowindex;     label label1 = (label)gridview1.rows[index].findcontrol("lblfield");     label1.text="abc";  }  protected void gridview1_rowdatabound(object sender, gridviewroweventargs e) {     if (e.row.rowtype == datacontrolrowtype.datarow)     {         //find dropdownlist in row         dropdownlist selectfield = (e.row.findcontrol("selectfield") dropdownlist);         string comboboxquery = "select field input_metadata";         datatable table = dataaccess.select(comboboxquery);         selectfield.datasource = table;         selectfield.datatextfield = "field";         selectfield.datavaluefield = "field";         selectfield.databind();         //add default item in dropdownlist         selectfield.items.insert(0, new listitem("please select"));     } } 

when select on dropdown want put sum text in column cells db values fetch

try this

gridview1.rows[currentrowindex].cells[0].value = "xyz"; 

edit

set autopostback="true" on dropdown this

<asp:dropdownlist id="selectfield" runat="server"  appenddatabounditems="true" onselectedindexchanged="dropdownlist1_selectedindexchanged" autopostback="true"></asp:dropdownlist> 

also change line in dropdownlist1_selectedindexchanged method.

label label1 = (label)gridview1.rows[index].findcontrol("lblfield"); 

you finding control id label1 while id lblfield.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -